Files
iac-homelab/terraform/prod/02-cloud-init.tf
Damien f3f84168c3 Remove legacy cloud-init template
The user-data.yml.tftpl file was replaced with OS-specific templates to
support
different init systems. The new templates are
user-data-systemd.yml.tftpl and
user-data-alpine.yml.tftpl, selected based on the VM's OS type.
2026-06-10 08:09:36 +02:00

45 lines
1.2 KiB
HCL

# File: terraform/prod/02-cloud-init.tf
locals {
# Use direct content if provided (CI), otherwise read from file (local).
ssh_public_key = var.admin_ssh_public_key != "" ? var.admin_ssh_public_key : file(var.admin_ssh_public_key_path)
# OS -> cloud-init template family mapping.
# Selects the correct user-data based on init system / package manager.
os_template_family = {
ubuntu = "systemd"
debian = "systemd"
rocky = "systemd"
ipfabric = "systemd"
alpine = "alpine"
}
}
resource "proxmox_virtual_environment_file" "cloud_config" {
for_each = var.virtual_machines
node_name = var.target_node
datastore_id = "local"
content_type = "snippets"
source_raw {
data = templatefile(
"${path.module}/../../cloud-init/user-data-${local.os_template_family[each.value.os]}.yml.tftpl",
{
# User information
username = lookup(each.value, "username", var.default_vm_user)
ssh_key = local.ssh_public_key
# VM information
hostname = "${each.key}.${var.domain_suffix}"
# Tailscale variables
vm_name = each.key
tailscale_auth_key = var.tailscale_auth_key
}
)
file_name = "${each.key}-cloud-init.yml"
}
}