Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
terraform/cluster.tf: allow to use both SSH public key files and text…
Browse files Browse the repository at this point in the history
… public keys

Currently, default value for ssh_keys variable is incorrect, as code
underneath expects it to be content of id_rsa.pub file and not the path
to this file.

This commit adds new variable 'ssh_key_files', which expects array of
SSH public key file paths, which is later expanded to the correct
content and merged with old 'ssh_keys' variable.

This gives user flexibility to specify either SSH key or SSH key file or
both if needed.

Signed-off-by: Mateusz Gozdek <[email protected]>
  • Loading branch information
invidian committed May 27, 2019
1 parent a5e3b40 commit bd47fbc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
17 changes: 14 additions & 3 deletions terraform/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ variable "facility" {
}
variable "ssh_keys" {
type = "list"
description = "List of SSH public key files or SSH public keys."
description = "List of SSH public keys."
default = []
}
variable "ssh_key_files" {
type = "list"
description = "List of SSH public key files."
default = [
"~/.ssh/id_rsa.pub"
]
Expand All @@ -49,7 +54,13 @@ variable "worker_node_count" {
description = "Number of worker nodes in the cluster. Must be 2 or higher."
default = "2"
}
resource "null_resource" "ssh_keys" {
count = "${length("${var.ssh_key_files}")}"

triggers = {
ssh_key = "${file("${var.ssh_key_files[count.index]}")}"
}
}
data "aws_route53_zone" "cluster" {
name = "${var.dns_zone}."

Expand Down Expand Up @@ -80,7 +91,7 @@ module "packet-svc-mesh-benchmark" {
dns_zone = "${var.dns_zone}"
dns_zone_id = "${data.aws_route53_zone.cluster.zone_id}"

ssh_keys = ["${var.ssh_keys}"]
ssh_keys = ["${var.ssh_keys}", "${null_resource.ssh_keys.*.triggers.ssh_key}"]
asset_dir = "../assets"

cluster_name = "${var.cluster_name}"
Expand Down Expand Up @@ -110,7 +121,7 @@ module "worker-pool-0" {
packet = "packet.default"
}

ssh_keys = ["${var.ssh_keys}"]
ssh_keys = ["${var.ssh_keys}", "${null_resource.ssh_keys.*.triggers.ssh_key}"]

cluster_name = "${var.cluster_name}"
project_id = "${var.packet_project_id}"
Expand Down
3 changes: 2 additions & 1 deletion terraform/variables.auto.tfvars.template
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ packet_project_id = "<packet project id>"
facility="ams1"
cluster_name="lokomotive-benchmark"

ssh_keys=["~/.ssh/id_rsa.pub"]
ssh_keys=["ssh-rsa AAAAB3NzaC1..."]
ssh_key_files=["~/.ssh/id_rsa.pub"]

controller_node_type = "t1.small"
worker_node_type = "t1.small"
Expand Down

0 comments on commit bd47fbc

Please sign in to comment.