# Cloud-init configuration for branch-specific bootstrap # # This file manages custom cloud-init snippets for VMs that need to bootstrap # from a specific git branch (non-master). Production VMs omit flake_branch # and use the default master branch. # Generate cloud-init snippets for VMs with custom branch configuration resource "local_file" "cloud_init_branch" { for_each = { for name, vm in local.vm_configs : name => vm if vm.flake_branch != null } filename = "${path.module}/.generated/cloud-init-${each.key}.yml" content = yamlencode({ # Write NIXOS_FLAKE_BRANCH to /etc/environment # This will be read by bootstrap.nix service via EnvironmentFile write_files = [{ path = "/etc/environment" content = "NIXOS_FLAKE_BRANCH=${each.value.flake_branch}\n" append = true }] }) file_permission = "0644" } # Upload cloud-init snippets to Proxmox # Note: This requires SSH access to the Proxmox host # Alternative: Manually copy files or use Proxmox API if available resource "null_resource" "upload_cloud_init" { for_each = { for name, vm in local.vm_configs : name => vm if vm.flake_branch != null } # Trigger re-upload when content changes triggers = { content_hash = local_file.cloud_init_branch[each.key].content } # Upload the cloud-init file to Proxmox snippets directory provisioner "local-exec" { command = <<-EOT scp -o StrictHostKeyChecking=no \ ${local_file.cloud_init_branch[each.key].filename} \ ${var.proxmox_host}:/var/lib/vz/snippets/cloud-init-${each.key}.yml EOT } depends_on = [local_file.cloud_init_branch] } # Ensure VMs depend on cloud-init being uploaded # This is handled implicitly by the cicustom reference in vms.tf