Files
iac-homelab/terraform/prod/02-cloud-init.tf
Damien 41dae6a086
Some checks failed
Terraform PR / Validate (pull_request) Successful in 5s
Terraform PR / Plan (pull_request) Has been cancelled
Add DNS server configuration for Alpine Linux
2026-06-10 08:49:50 +02:00

48 lines
1.4 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}"
# Network (used by templates that need to write /etc/resolv.conf themselves, e.g. Alpine)
dns_server = var.dns_servers[0]
# Tailscale variables
vm_name = each.key
tailscale_auth_key = var.tailscale_auth_key
}
)
file_name = "${each.key}-cloud-init.yml"
}
}