uses existing hetzner api key
Some checks failed
Deployment / deploy-docker (push) Failing after 9s

This commit is contained in:
Melchior Reimers
2026-02-04 19:44:00 +01:00
parent f4ba752445
commit 2802827e60
3 changed files with 12 additions and 5 deletions

10
main.tf
View File

@@ -1,11 +1,11 @@
# SSH Key
resource "hcloud_ssh_key" "default" {
name = "${var.server_name}-ssh-key"
public_key = var.ssh_public_key
# SSH Key (existing)
data "hcloud_ssh_key" "default" {
name = local.ssh_key_name
}
# Cloud-init script
locals {
ssh_key_name = length(trimspace(var.ssh_key_name)) > 0 ? var.ssh_key_name : "${var.server_name}-ssh-key"
user_data = templatefile("${path.module}/scripts/cloud-init.sh", {
username = var.username
ssh_public_key = var.ssh_public_key
@@ -21,7 +21,7 @@ resource "hcloud_server" "vps" {
image = var.image
server_type = data.hcloud_server_type.selected.name
location = data.hcloud_location.selected.name
ssh_keys = concat([hcloud_ssh_key.default.id])
ssh_keys = concat([data.hcloud_ssh_key.default.id])
user_data = local.user_data
labels = {