diff --git a/terraform/locals.tf b/terraform/locals.tf index d690b6c..376b447 100644 --- a/terraform/locals.tf +++ b/terraform/locals.tf @@ -2,27 +2,27 @@ locals { # Get current DHCP IPs from QEMU guest agent (from VM resource computed attribute) # Find first non-loopback, non-empty IP address from any interface controlplane_dhcp_ips = [ - for vm in proxmox_virtual_environment_vm.controlplane : + for vm in proxmox_virtual_environment_vm.controlplane : flatten([ - for iface_ips in vm.ipv4_addresses : + for iface_ips in vm.ipv4_addresses : [for ip in iface_ips : ip if ip != "127.0.0.1"] ])[0] ] - + worker_dhcp_ips = [ - for vm in proxmox_virtual_environment_vm.worker : + for vm in proxmox_virtual_environment_vm.worker : flatten([ - for iface_ips in vm.ipv4_addresses : + for iface_ips in vm.ipv4_addresses : [for ip in iface_ips : ip if ip != "127.0.0.1"] ])[0] ] - + # Use DHCP IPs for initial connection and configuration apply # Note: If static IPs are configured via var.controlplane_ips/var.worker_ips, # Talos will reconfigure the network after initial apply, but we connect via DHCP controlplane_ips = local.controlplane_dhcp_ips worker_ips = local.worker_dhcp_ips - + # For client config and bootstrap, use static IPs if configured, otherwise DHCP controlplane_endpoints = length(var.controlplane_ips) > 0 ? var.controlplane_ips : local.controlplane_dhcp_ips diff --git a/terraform/main.tf b/terraform/main.tf index 3f657b6..3eb1b0e 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -173,7 +173,7 @@ resource "talos_machine_configuration_apply" "controlplane" { config_patches = concat( [ templatefile("${path.module}/templates/install-disk-and-hostname.yaml.tmpl", { - hostname = "${var.cluster_name}-cp-${count.index + 1}" + hostname = "${var.cluster_name}-cp-${count.index + 1}" }), templatefile("${path.module}/templates/proxmox-ccm.yaml.tmpl", { proxmox_url = var.proxmox_endpoint @@ -213,7 +213,7 @@ resource "talos_machine_configuration_apply" "worker" { config_patches = concat( [ templatefile("${path.module}/templates/install-disk-and-hostname.yaml.tmpl", { - hostname = "${var.cluster_name}-worker-${count.index + 1}" + hostname = "${var.cluster_name}-worker-${count.index + 1}" }), templatefile("${path.module}/templates/proxmox-ccm.yaml.tmpl", { proxmox_url = var.proxmox_endpoint