48 lines
1.7 KiB
Text
48 lines
1.7 KiB
Text
#!/usr/bin/env nu
|
|
# Derived variables for cap bundle rendering.
|
|
# Reads the component JSON, outputs extra Tera context vars as JSON.
|
|
|
|
def zone_to_cf_secret [zone: string]: nothing -> string {
|
|
$"dns-($zone | str replace --all '.' '-')"
|
|
}
|
|
|
|
def resolve_fip_ip [fip_name: string]: nothing -> string {
|
|
let result = (do { ^hcloud floating-ip list -o json } | complete)
|
|
if $result.exit_code != 0 { return "" }
|
|
let matched = ($result.stdout | from json | where name == $fip_name)
|
|
if ($matched | is-empty) { return "" }
|
|
$matched | first | get ip
|
|
}
|
|
|
|
def main [component_json: string]: nothing -> nothing {
|
|
let d = ($component_json | from json)
|
|
|
|
let dns_zone = ($d | get -o dns_zone | default "")
|
|
let gateway_fip = ($d | get -o gateway_fip | default "")
|
|
let gateway_ip = ($d | get -o gateway_ip | default "")
|
|
let name = ($d | get -o name | default "cap")
|
|
let namespace = ($d | get -o namespace | default "cap-svc")
|
|
|
|
let resolved_cf_secret = if ($dns_zone | is-not-empty) {
|
|
zone_to_cf_secret $dns_zone
|
|
} else { "" }
|
|
|
|
let resolved_gateway_ip = if ($gateway_ip | is-not-empty) {
|
|
$gateway_ip
|
|
} else if ($gateway_fip | is-not-empty) {
|
|
resolve_fip_ip $gateway_fip
|
|
} else { "" }
|
|
|
|
if ($resolved_gateway_ip | is-empty) and ($gateway_fip | is-not-empty) {
|
|
print $"[warn] vars: could not resolve IP for gateway FIP '($gateway_fip)' — DNS reconcile will be skipped"
|
|
}
|
|
|
|
{
|
|
cf_secret_name: $resolved_cf_secret,
|
|
gateway_ip: $resolved_gateway_ip,
|
|
tls_secret: $"($name)-tls",
|
|
redis_url: $"redis://($name)-valkey.($namespace).svc.libre-wuji.local:6379",
|
|
}
|
|
| to json --raw
|
|
| print
|
|
}
|