49 lines
1.7 KiB
Text
49 lines
1.7 KiB
Text
|
|
#!/usr/bin/env nu
|
||
|
|
# Derived variables for rev_proxy 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 fip_name = ($d | get -o fip_name | default "librecloud-fip-rvprxy")
|
||
|
|
let sites = ($d | get -o sites | default [])
|
||
|
|
|
||
|
|
let fip_ip = resolve_fip_ip $fip_name
|
||
|
|
|
||
|
|
# Hard prerequisite: the FIP must exist and be assigned an IP before deploy.
|
||
|
|
# Without it the LoadBalancer Service gets no loadBalancerIP and DNS update
|
||
|
|
# silently points nowhere.
|
||
|
|
if ($fip_ip | is-empty) {
|
||
|
|
error make {
|
||
|
|
msg: $"rev_proxy prerequisite not met: floating IP '($fip_name)' not found or has no IP assigned. Provision it via bootstrap before deploying.",
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Derive cf_secret_name from the first site's dns_zone, if any.
|
||
|
|
let cf_secret_name = if ($sites | is-not-empty) {
|
||
|
|
let first_zone = ($sites | first | get -o dns_zone | default "")
|
||
|
|
if ($first_zone | is-not-empty) {
|
||
|
|
zone_to_cf_secret $first_zone
|
||
|
|
} else { "" }
|
||
|
|
} else { "" }
|
||
|
|
|
||
|
|
{
|
||
|
|
fip_ip: $fip_ip,
|
||
|
|
cf_secret_name: $cf_secret_name,
|
||
|
|
}
|
||
|
|
| to json --raw
|
||
|
|
| print
|
||
|
|
}
|