Skip to content

Commit

Permalink
add key generation to all demos
Browse files Browse the repository at this point in the history
  • Loading branch information
zseta committed Feb 24, 2025
1 parent 6ca9044 commit da49282
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion scylladb-cloud/scylladb-cloud.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ resource "local_file" "grafana_urls" {
}

# Generate private key file for Ansible
resource "local_file" "file_ansible_config" {
resource "local_file" "keyfile_ansible_config" {
content = <<-DOC
-----BEGIN RSA PRIVATE KEY-----
${tls_private_key.example.private_key_pem}
Expand Down
12 changes: 6 additions & 6 deletions tablets-scaling/monitoring.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resource "aws_instance" "scylladb-monitoring" {
ami = var.monitoring_ami_id
instance_type = var.monitoring_instance_type
key_name = var.aws_key_pair
key_name = aws_key_pair.generated_key.key_name

security_groups = [aws_security_group.sg.id]
subnet_id = element(aws_subnet.public_subnet.*.id, 0)
Expand All @@ -23,7 +23,7 @@ resource "aws_instance" "scylladb-monitoring" {
connection {
type = "ssh"
user = var.instance_username_monitoring
private_key = file(var.ssh_private_key)
private_key = tls_private_key.private_key.private_key_pem
host = self.public_ip
}
}
Expand All @@ -39,7 +39,7 @@ resource "aws_instance" "scylladb-monitoring" {
connection {
type = "ssh"
user = var.instance_username_monitoring
private_key = file(var.ssh_private_key)
private_key = tls_private_key.private_key.private_key_pem
host = self.public_ip
}
}
Expand All @@ -53,7 +53,7 @@ resource "aws_instance" "scylladb-monitoring" {
connection {
type = "ssh"
user = var.instance_username_monitoring
private_key = file(var.ssh_private_key)
private_key = tls_private_key.private_key.private_key_pem
host = self.public_ip
}
}
Expand All @@ -71,15 +71,15 @@ resource "aws_instance" "scylladb-monitoring" {
connection {
type = "ssh"
user = var.instance_username_monitoring
private_key = file(var.ssh_private_key)
private_key = tls_private_key.private_key.private_key_pem
host = self.public_ip
}
}

connection {
type = "ssh"
user = var.instance_username_monitoring
private_key = file(var.ssh_private_key)
private_key = tls_private_key.private_key.private_key_pem
host = self.public_ip
}
}
Expand Down
31 changes: 26 additions & 5 deletions tablets-scaling/scylladb-instances.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@

resource "tls_private_key" "private_key" {
algorithm = "RSA"
rsa_bits = 4096
}

resource "aws_key_pair" "generated_key" {
key_name = "ScyllaDB-Enterprise-DEMO-key"
public_key = tls_private_key.private_key.public_key_openssh
}

resource "aws_instance" "scylladb_seed" {
count = 1
ami = var.scylla_ami_id
instance_type = var.scylla_node_type
key_name = var.aws_key_pair
key_name = aws_key_pair.generated_key.key_name

subnet_id = element(aws_subnet.public_subnet.*.id, count.index)
security_groups = [aws_security_group.sg.id]
Expand Down Expand Up @@ -40,7 +50,7 @@ EOF
connection {
type = "ssh"
user = "ubuntu"
private_key = file(var.ssh_private_key)
private_key = tls_private_key.private_key.private_key_pem
host = coalesce(self.public_ip, self.private_ip)
agent = true
}
Expand All @@ -51,7 +61,7 @@ resource "aws_instance" "scylladb_nonseeds" {
count = var.scylla_node_count - 1
ami = var.scylla_ami_id
instance_type = var.scylla_node_type
key_name = var.aws_key_pair
key_name = aws_key_pair.generated_key.key_name

subnet_id = element(aws_subnet.public_subnet.*.id, count.index)
security_groups = [aws_security_group.sg.id]
Expand All @@ -77,6 +87,17 @@ EOF
depends_on = [aws_instance.scylladb_seed]
}

# Generate private key file for Ansible
resource "local_file" "keyfile_ansible_config" {
content = <<-DOC
-----BEGIN RSA PRIVATE KEY-----
${tls_private_key.private_key.private_key_pem}
-----END RSA PRIVATE KEY-----
DOC
filename = "./ansible/key.pem"
}

# Gerenate Ansible config file
resource "local_file" "file_ansible_config" {
content = <<-DOC
Expand All @@ -89,8 +110,8 @@ resource "local_file" "file_ansible_config" {
host_key_checking=False
interpreter_python=auto_silent
force_valid_group_names=ignore
private_key_file=${var.ssh_private_key}
remote_user=${var.instance_username}
private_key_file=key.pem
remote_user=scyllaadm
DOC
filename = "./ansible/ansible.cfg"
Expand Down
4 changes: 2 additions & 2 deletions tablets-scaling/scylladb-loaders.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resource "aws_instance" "loader_instance" {
instance_type = var.loader_instance_type
subnet_id = element(aws_subnet.public_subnet.*.id, count.index)
security_groups = [aws_security_group.sg.id, ]
key_name = var.aws_key_pair
key_name = aws_key_pair.generated_key.key_name
tags = {
"Name" = "${var.custom_name}-Loader-${count.index}"
"CreatedBy" = "scylladb-demo"
Expand Down Expand Up @@ -51,7 +51,7 @@ resource "aws_instance" "loader_instance" {
connection {
type = "ssh"
user = "ubuntu"
private_key = file(var.ssh_private_key)
private_key = tls_private_key.private_key.private_key_pem
host = coalesce(self.public_ip, self.private_ip)
agent = true
}
Expand Down
13 changes: 0 additions & 13 deletions tablets-scaling/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@ variable "aws_creds_profile" {
default = ""
}

# SSH private key for EC2 instance access
variable "ssh_private_key" {
description = "SSH private key location for EC2 instance access"
type = string
default = ""
}

variable "aws_key_pair" {
description = "Key pair name in AWS"
type = string
default = ""
}

variable "region" {
description = "AWS region"
type = string
Expand Down

0 comments on commit da49282

Please sign in to comment.