Skip to content

Commit da49282

Browse files
committed
add key generation to all demos
1 parent 6ca9044 commit da49282

File tree

5 files changed

+35
-27
lines changed

5 files changed

+35
-27
lines changed

scylladb-cloud/scylladb-cloud.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ resource "local_file" "grafana_urls" {
6565
}
6666

6767
# Generate private key file for Ansible
68-
resource "local_file" "file_ansible_config" {
68+
resource "local_file" "keyfile_ansible_config" {
6969
content = <<-DOC
7070
-----BEGIN RSA PRIVATE KEY-----
7171
${tls_private_key.example.private_key_pem}

tablets-scaling/monitoring.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
resource "aws_instance" "scylladb-monitoring" {
22
ami = var.monitoring_ami_id
33
instance_type = var.monitoring_instance_type
4-
key_name = var.aws_key_pair
4+
key_name = aws_key_pair.generated_key.key_name
55

66
security_groups = [aws_security_group.sg.id]
77
subnet_id = element(aws_subnet.public_subnet.*.id, 0)
@@ -23,7 +23,7 @@ resource "aws_instance" "scylladb-monitoring" {
2323
connection {
2424
type = "ssh"
2525
user = var.instance_username_monitoring
26-
private_key = file(var.ssh_private_key)
26+
private_key = tls_private_key.private_key.private_key_pem
2727
host = self.public_ip
2828
}
2929
}
@@ -39,7 +39,7 @@ resource "aws_instance" "scylladb-monitoring" {
3939
connection {
4040
type = "ssh"
4141
user = var.instance_username_monitoring
42-
private_key = file(var.ssh_private_key)
42+
private_key = tls_private_key.private_key.private_key_pem
4343
host = self.public_ip
4444
}
4545
}
@@ -53,7 +53,7 @@ resource "aws_instance" "scylladb-monitoring" {
5353
connection {
5454
type = "ssh"
5555
user = var.instance_username_monitoring
56-
private_key = file(var.ssh_private_key)
56+
private_key = tls_private_key.private_key.private_key_pem
5757
host = self.public_ip
5858
}
5959
}
@@ -71,15 +71,15 @@ resource "aws_instance" "scylladb-monitoring" {
7171
connection {
7272
type = "ssh"
7373
user = var.instance_username_monitoring
74-
private_key = file(var.ssh_private_key)
74+
private_key = tls_private_key.private_key.private_key_pem
7575
host = self.public_ip
7676
}
7777
}
7878

7979
connection {
8080
type = "ssh"
8181
user = var.instance_username_monitoring
82-
private_key = file(var.ssh_private_key)
82+
private_key = tls_private_key.private_key.private_key_pem
8383
host = self.public_ip
8484
}
8585
}

tablets-scaling/scylladb-instances.tf

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11

2+
resource "tls_private_key" "private_key" {
3+
algorithm = "RSA"
4+
rsa_bits = 4096
5+
}
6+
7+
resource "aws_key_pair" "generated_key" {
8+
key_name = "ScyllaDB-Enterprise-DEMO-key"
9+
public_key = tls_private_key.private_key.public_key_openssh
10+
}
11+
212
resource "aws_instance" "scylladb_seed" {
313
count = 1
414
ami = var.scylla_ami_id
515
instance_type = var.scylla_node_type
6-
key_name = var.aws_key_pair
16+
key_name = aws_key_pair.generated_key.key_name
717

818
subnet_id = element(aws_subnet.public_subnet.*.id, count.index)
919
security_groups = [aws_security_group.sg.id]
@@ -40,7 +50,7 @@ EOF
4050
connection {
4151
type = "ssh"
4252
user = "ubuntu"
43-
private_key = file(var.ssh_private_key)
53+
private_key = tls_private_key.private_key.private_key_pem
4454
host = coalesce(self.public_ip, self.private_ip)
4555
agent = true
4656
}
@@ -51,7 +61,7 @@ resource "aws_instance" "scylladb_nonseeds" {
5161
count = var.scylla_node_count - 1
5262
ami = var.scylla_ami_id
5363
instance_type = var.scylla_node_type
54-
key_name = var.aws_key_pair
64+
key_name = aws_key_pair.generated_key.key_name
5565

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

90+
# Generate private key file for Ansible
91+
resource "local_file" "keyfile_ansible_config" {
92+
content = <<-DOC
93+
-----BEGIN RSA PRIVATE KEY-----
94+
${tls_private_key.private_key.private_key_pem}
95+
-----END RSA PRIVATE KEY-----
96+
97+
DOC
98+
filename = "./ansible/key.pem"
99+
}
100+
80101
# Gerenate Ansible config file
81102
resource "local_file" "file_ansible_config" {
82103
content = <<-DOC
@@ -89,8 +110,8 @@ resource "local_file" "file_ansible_config" {
89110
host_key_checking=False
90111
interpreter_python=auto_silent
91112
force_valid_group_names=ignore
92-
private_key_file=${var.ssh_private_key}
93-
remote_user=${var.instance_username}
113+
private_key_file=key.pem
114+
remote_user=scyllaadm
94115
95116
DOC
96117
filename = "./ansible/ansible.cfg"

tablets-scaling/scylladb-loaders.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ resource "aws_instance" "loader_instance" {
77
instance_type = var.loader_instance_type
88
subnet_id = element(aws_subnet.public_subnet.*.id, count.index)
99
security_groups = [aws_security_group.sg.id, ]
10-
key_name = var.aws_key_pair
10+
key_name = aws_key_pair.generated_key.key_name
1111
tags = {
1212
"Name" = "${var.custom_name}-Loader-${count.index}"
1313
"CreatedBy" = "scylladb-demo"
@@ -51,7 +51,7 @@ resource "aws_instance" "loader_instance" {
5151
connection {
5252
type = "ssh"
5353
user = "ubuntu"
54-
private_key = file(var.ssh_private_key)
54+
private_key = tls_private_key.private_key.private_key_pem
5555
host = coalesce(self.public_ip, self.private_ip)
5656
agent = true
5757
}

tablets-scaling/variables.tf

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@ variable "aws_creds_profile" {
1616
default = ""
1717
}
1818

19-
# SSH private key for EC2 instance access
20-
variable "ssh_private_key" {
21-
description = "SSH private key location for EC2 instance access"
22-
type = string
23-
default = ""
24-
}
25-
26-
variable "aws_key_pair" {
27-
description = "Key pair name in AWS"
28-
type = string
29-
default = ""
30-
}
31-
3219
variable "region" {
3320
description = "AWS region"
3421
type = string

0 commit comments

Comments
 (0)