#!/usr/bin/env bash set -euo pipefail repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" dynu_dir="${repo_root}/infrastructure/terraform/dynu" out_json="${dynu_dir}/generated/dynu_dns_records_inventory.json" if [[ ! -d "${dynu_dir}" ]]; then echo "ERROR: Dynu Terraform directory not found at ${dynu_dir}." >&2 exit 1 fi if ! command -v terraform >/dev/null 2>&1; then echo "ERROR: terraform is required to refresh Dynu DNS inventory." >&2 exit 1 fi mkdir -p "$(dirname "${out_json}")" ( cd "${dynu_dir}" if terraform output -json dynu_dns_inventory > "${out_json}"; then : elif terraform output -json dynu_dns_records_catalog > "${out_json}"; then : else echo "ERROR: Failed to export Dynu DNS inventory from Terraform outputs. Tried: dynu_dns_inventory, dynu_dns_records_catalog." >&2 echo "Run 'cd infrastructure/terraform/dynu && terraform output' to inspect available outputs." >&2 exit 1 fi ) if [[ ! -s "${out_json}" ]]; then echo "ERROR: Dynu DNS inventory output file is empty: ${out_json}" >&2 exit 1 fi echo "Generated: ${out_json}"