From 718a9930e85bbc6830d3e473598b0752319d3149 Mon Sep 17 00:00:00 2001 From: MichaelFisher1997 Date: Sun, 1 Mar 2026 18:00:59 +0000 Subject: [PATCH] fix: fail fast when terraform node IP outputs are empty --- .../render-inventory-from-tf-output.py | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/nixos/kubeadm/scripts/render-inventory-from-tf-output.py b/nixos/kubeadm/scripts/render-inventory-from-tf-output.py index b911877..e5c8cf7 100755 --- a/nixos/kubeadm/scripts/render-inventory-from-tf-output.py +++ b/nixos/kubeadm/scripts/render-inventory-from-tf-output.py @@ -18,6 +18,28 @@ def map_to_pairs(items: dict[str, str]) -> str: return " ".join(f"{k}={v}" for k, v in ordered) +def require_non_empty_ips(label: str, items: dict[str, str]) -> dict[str, str]: + cleaned: dict[str, str] = {} + missing: list[str] = [] + + for name, ip in items.items(): + ip_value = (ip or "").strip() + if not ip_value: + missing.append(name) + continue + cleaned[name] = ip_value + + if missing: + names = ", ".join(sorted(missing, key=natural_key)) + raise SystemExit( + f"Missing IPv4 addresses for {label}: {names}. " + "Terraform outputs are present but empty. " + "This usually means Proxmox guest IP discovery is unavailable for these VMs yet." + ) + + return cleaned + + def main() -> int: payload = json.load(sys.stdin) @@ -25,7 +47,10 @@ def main() -> int: wk_map = payload.get("worker_vm_ipv4", {}).get("value", {}) if not cp_map or not wk_map: - raise SystemExit("Missing control_plane_vm_ipv4 or worker_vm_ipv4 in terraform output") + raise SystemExit("Missing control_plane_vm_ipv4 or worker_vm_ipv4 in terraform output") + + cp_map = require_non_empty_ips("control planes", cp_map) + wk_map = require_non_empty_ips("workers", wk_map) ssh_user = os.environ.get("KUBEADM_SSH_USER", "").strip() or "micqdf"