Skip to content

Commit

Permalink
fix: deletion of test environment
Browse files Browse the repository at this point in the history
  • Loading branch information
batthebee committed Apr 12, 2022
1 parent 83be896 commit 1ff8e97
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ output "lb_address" {

output "hcloud_ssh_key_public" {
description = "registered ssh public key on your Hetzner Cloud machines."
value = var.hcloud_ssh_key_public != "" && var.hcloud_ssh_key_private != "" ? var.hcloud_ssh_key_public : tls_private_key.ssh_key_gen[0].public_key_openssh
value = local.public_key
}

output "hcloud_ssh_key_private" {
description = "registered ssh private key on your Hetzner Cloud machines."
value = var.hcloud_ssh_key_public != "" && var.hcloud_ssh_key_private != "" ? var.hcloud_ssh_key_private : tls_private_key.ssh_key_gen[0].private_key_openssh
value = local.private_key
}
10 changes: 2 additions & 8 deletions resources_hetzner.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@ resource "hcloud_network" "kubernetes_internal_network" {
}
}

resource "tls_private_key" "ssh_key_gen" {
count = var.hcloud_ssh_key_public != "" && var.hcloud_ssh_key_private != "" ? 1 : 0
algorithm = "RSA"
rsa_bits = 4096
}

resource "hcloud_ssh_key" "rke_ssh_key" {
name = "${var.instance_prefix}-rke-management-key"
public_key = var.hcloud_ssh_key_public != "" && var.hcloud_ssh_key_private != "" ? var.hcloud_ssh_key_public : tls_private_key.ssh_key_gen[0].public_key_openssh
public_key = local.public_key
labels = {
automated = true
}
Expand All @@ -44,7 +38,7 @@ resource "hcloud_server" "rke_nodes" {
connection {
type = "ssh"
user = "root"
private_key = var.hcloud_ssh_key_public != "" && var.hcloud_ssh_key_private != "" ? var.hcloud_ssh_key_private : tls_private_key.ssh_key_gen[0].private_key_openssh
private_key = local.private_key
host = self.ipv4_address
}
}
Expand Down
2 changes: 1 addition & 1 deletion resources_rke.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ resource "rke_cluster" "rke_cluster" {
role = ["controlplane", "worker", "etcd"]
user = "root"
ssh_agent_auth = true
ssh_key = var.hcloud_ssh_key_private
ssh_key = local.private_key
}
}

Expand Down
8 changes: 8 additions & 0 deletions resources_ssh_keys.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "tls_private_key" "ssh_key_gen" {
algorithm = "ED25519"
}

locals {
public_key = var.hcloud_ssh_key_public != "" && var.hcloud_ssh_key_private != "" ? var.hcloud_ssh_key_public : tls_private_key.ssh_key_gen.public_key_openssh
private_key = var.hcloud_ssh_key_public != "" && var.hcloud_ssh_key_private != "" ? var.hcloud_ssh_key_private : tls_private_key.ssh_key_gen.private_key_openssh
}

0 comments on commit 1ff8e97

Please sign in to comment.