Files
HetznerTerra/terraform/ssh.tf
MichaelFisher1997 a42653b370
Some checks failed
Deploy Cluster / Terraform (push) Failing after 20s
Deploy Cluster / Ansible (push) Has been skipped
fix: Use eu-central network zone, handle existing SSH key
2026-02-28 21:54:49 +00:00

23 lines
622 B
HCL

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
}