From 1607387529406b9b9247929772981639e44b827c Mon Sep 17 00:00:00 2001 From: MichaelFisher1997 Date: Sat, 28 Feb 2026 21:58:19 +0000 Subject: [PATCH] fix: Simplify SSH key handling - delete existing key from Hetzner first --- terraform/servers.tf | 4 ++-- terraform/ssh.tf | 14 -------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/terraform/servers.tf b/terraform/servers.tf index 5b72730..e4f5535 100644 --- a/terraform/servers.tf +++ b/terraform/servers.tf @@ -10,7 +10,7 @@ resource "hcloud_server" "control_plane" { server_type = var.control_plane_type image = data.hcloud_image.ubuntu.id location = var.location - ssh_keys = [data.hcloud_ssh_key.cluster.id] + ssh_keys = [hcloud_ssh_key.cluster.id] labels = { cluster = var.cluster_name @@ -37,7 +37,7 @@ resource "hcloud_server" "workers" { server_type = var.worker_type image = data.hcloud_image.ubuntu.id location = var.location - ssh_keys = [data.hcloud_ssh_key.cluster.id] + ssh_keys = [hcloud_ssh_key.cluster.id] labels = { cluster = var.cluster_name diff --git a/terraform/ssh.tf b/terraform/ssh.tf index 4e9c475..7041784 100644 --- a/terraform/ssh.tf +++ b/terraform/ssh.tf @@ -2,21 +2,7 @@ data "local_file" "ssh_public_key" { filename = pathexpand(var.ssh_public_key) } -data "hcloud_ssh_keys" "all_keys" {} - -locals { - existing_key = try([ - for key in data.hcloud_ssh_keys.all_keys.ssh_keys : - key if key.name == "${var.cluster_name}-ssh-key" - ][0], null) -} - resource "hcloud_ssh_key" "cluster" { - count = local.existing_key == null ? 1 : 0 name = "${var.cluster_name}-ssh-key" public_key = data.local_file.ssh_public_key.content } - -data "hcloud_ssh_key" "cluster" { - fingerprint = local.existing_key != null ? local.existing_key.fingerprint : hcloud_ssh_key.cluster[0].fingerprint -}