Files
homelab/scripts/validate_plan.py
T

49 lines
1.7 KiB
Python

import json
import sys
def validate_plan(json_file_path):
try:
with open(json_file_path, 'r') as f:
plan = json.load(f)
except FileNotFoundError:
print(f"Error: File {json_file_path} not found.")
sys.exit(1)
# planned_values contains the state AFTER the plan is applied
root_module = plan.get('planned_values', {}).get('root_module', {})
resources = root_module.get('resources', [])
# Check 1: Gitea Server must verify exist (VMID 114)
# Resource address: proxmox_lxc.lxc["114"]
gitea_exists = False
for res in resources:
if res.get('address') == 'proxmox_lxc.lxc["114"]':
gitea_exists = True
break
if not gitea_exists:
print("ERROR: Validation Failed! Gitea server (proxmox_lxc.lxc[\"114\"]) is missing in the planned state (it might be deleted).")
sys.exit(1)
# Check 2: At least one runner must remain
# Runner address pattern: proxmox_lxc.runners[...]
# We check if any resource starting with proxmox_lxc.runners exists in planned_values
runner_count = 0
for res in resources:
if res.get('address', '').startswith('proxmox_lxc.runners'):
runner_count += 1
if runner_count < 1:
print("ERROR: Validation Failed! No Gitea runners (proxmox_lxc.runners) found in the planned state.")
sys.exit(1)
print(f"Validation Successful: Gitea server exists and {runner_count} runners will be present.")
sys.exit(0)
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python validate_plan.py <plan.json>")
sys.exit(1)
validate_plan(sys.argv[1])