provisioning-catalog/components/static_web/cluster/vars.nu

49 lines
1.8 KiB
Text
Executable file

#!/usr/bin/env nu
# Derived variables for static_web 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 "static-web")
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 { "" }
# The Cilium Gateway FIP (gateway_fip) is part of the base cluster infra and
# expected to be operational. If the IP can't be resolved, DNS update will be
# skipped at deploy time but the HTTPRoute and Gateway will still function.
if ($resolved_gateway_ip | is-empty) and ($gateway_fip | is-not-empty) {
print $"[warn] vars: could not resolve IP for gateway FIP '($gateway_fip)' — STATICWEB_GATEWAY_IP will be empty, DNS reconcile will be skipped"
}
{
cf_secret_name: $resolved_cf_secret,
gateway_ip: $resolved_gateway_ip,
tls_secret: $"($name)-tls",
}
| to json --raw
| print
}