#!/usr/bin/env nu # Derived variables for wireguard bundle rendering. # Resolves fip_name → lb_ipam_ip via hcloud CLI and derives wg-easy address template. def main [component_json: string]: nothing -> nothing { let wg = ($component_json | from json) let preconfigured = ($wg | get -o lb_ipam_ip | default "" | into string) let lb_ipam_ip = if ($preconfigured | is-not-empty) { $preconfigured } else { let fip_name = ($wg | get -o fip_name | default "") if ($fip_name | is-not-empty) { let result = (do { hcloud floating-ip list -o json } | complete) if $result.exit_code == 0 { let fips = ($result.stdout | from json) let matched = ($fips | where name == $fip_name) if ($matched | is-not-empty) { $matched | first | get ip } else { error make { msg: $"FIP '($fip_name)' not found in Hetzner account" } } } else { error make { msg: $"hcloud failed: ($result.stderr)" } } } else { "" } } let server_ip = ($wg | get -o server_ip | default "10.200.0.1") let wg_default_address = ($server_ip | str replace --regex '\d+$' 'x') { lb_ipam_ip: $lb_ipam_ip, wg_default_address: $wg_default_address, } | to json --raw | print }