Some checks failed
Terraform Plan / Terraform Plan (push) Has been cancelled
66 lines
1.8 KiB
Python
Executable File
66 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import json
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
|
|
def natural_key(name: str):
|
|
m = re.match(r"^([a-zA-Z-]+)-(\d+)$", name)
|
|
if m:
|
|
return (m.group(1), int(m.group(2)))
|
|
return (name, 0)
|
|
|
|
|
|
def map_to_pairs(items: dict[str, str]) -> str:
|
|
ordered = sorted(items.items(), key=lambda kv: natural_key(kv[0]))
|
|
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)
|
|
|
|
cp_map = payload.get("control_plane_vm_ipv4", {}).get("value", {})
|
|
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")
|
|
|
|
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"
|
|
|
|
print(f"SSH_USER={ssh_user}")
|
|
print("PRIMARY_CONTROL_PLANE=cp-1")
|
|
print(f"CONTROL_PLANES=\"{map_to_pairs(cp_map)}\"")
|
|
print(f"WORKERS=\"{map_to_pairs(wk_map)}\"")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|