Skip to content

Commit

Permalink
feat: write public key to local file (#17)
Browse files Browse the repository at this point in the history
- Create a local file with the public key in addition to the private
key.
- Add outputs for both file paths
  • Loading branch information
apricote authored Jul 3, 2024
1 parent df359ff commit 88395fd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion main-infra.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ resource "tls_private_key" "ssh" {
algorithm = "ED25519"
}

resource "local_sensitive_file" "ssh" {
resource "local_sensitive_file" "ssh_private" {
content = tls_private_key.ssh.private_key_openssh
filename = abspath("${path.root}/files/id_ed25519")
}

resource "local_sensitive_file" "ssh_public" {
content = tls_private_key.ssh.public_key_openssh
filename = abspath("${path.root}/files/id_ed25519.pub")
}

resource "hcloud_ssh_key" "default" {
name = var.name
public_key = tls_private_key.ssh.public_key_openssh
Expand Down
4 changes: 2 additions & 2 deletions main-setup.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ resource "null_resource" "k3sup_control" {
provisioner "local-exec" {
command = <<-EOT
k3sup install --print-config=false \
--ssh-key='${local_sensitive_file.ssh.filename}' \
--ssh-key='${local_sensitive_file.ssh_private.filename}' \
--ip='${hcloud_server.control.ipv4_address}' \
--k3s-channel='${var.k3s_channel}' \
--k3s-extra-args="\
Expand Down Expand Up @@ -78,7 +78,7 @@ resource "null_resource" "k3sup_worker" {
provisioner "local-exec" {
command = <<-EOT
k3sup join \
--ssh-key='${local_sensitive_file.ssh.filename}' \
--ssh-key='${local_sensitive_file.ssh_private.filename}' \
--ip='${hcloud_server.worker[count.index].ipv4_address}' \
--server-ip='${hcloud_server.control.ipv4_address}' \
--k3s-channel='${var.k3s_channel}' \
Expand Down
9 changes: 9 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "ssh_private_key_filename" {
description = "Path to the private SSH Key"
value = local_sensitive_file.ssh_private.filename
}

output "ssh_public_key_filename" {
description = "Path to the public SSH Key"
value = local_sensitive_file.ssh_public.filename
}

0 comments on commit 88395fd

Please sign in to comment.