diff --git a/modules/infrastructure/output.tf b/modules/infrastructure/output.tf index 9b9b77a..8eb9d06 100644 --- a/modules/infrastructure/output.tf +++ b/modules/infrastructure/output.tf @@ -3,6 +3,7 @@ output "hosts" { for key, host in var.hosts : key => { "hostname" = host.hostname + "provider" = host.provider "fqdn" = "${host.hostname}.serguzim.net" "fqdn_vpn" = "${host.hostname}.vpn.serguzim.net" "ipv4_address" = try( diff --git a/visualize.py b/visualize.py index cfb951a..e1f2dae 100755 --- a/visualize.py +++ b/visualize.py @@ -31,35 +31,35 @@ def get_icon(svc): fmt = icon_format.get(svc, 'svg') return f'https://cdn.jsdelivr.net/gh/selfhst/icons/{fmt}/{svc}.{fmt}' -def service_key(svc, data): - return f"'serguzim.net'.{data['host']}.{svc}" -def host_key(host): - return f"'serguzim.net'.{host}" +def host_key(host, hosts): + return f"'serguzim.net'.{hosts[host]["provider"]}.{host}" +def service_key(svc, data, hosts): + return f"{host_key(data["host"], hosts)}.{svc}" -def service_key_find(svc_name, services): +def service_key_find(svc_name, services, hosts): for svc, data in services.items(): if svc == svc_name: - return service_key(svc, data) + return service_key(svc, data, hosts) return None def parse_hosts(hosts): result = [] for host, data in hosts.items(): result.append({ - 'key': host_key(host), + 'key': host_key(host, hosts), 'name': host, }) return result -def parse_services(services): +def parse_services(services, hosts): result = [] - postgresql_key = service_key_find("postgresql", services) - authentik_key = service_key_find("authentik", services) + postgresql_key = service_key_find("postgresql", services, hosts) + authentik_key = service_key_find("authentik", services, hosts) for svc, data in services.items(): - svc_key = service_key(svc, data) + svc_key = service_key(svc, data, hosts) domains = [] for dns in data.get("dns") or []: @@ -83,19 +83,21 @@ if __name__ == '__main__': data = json.loads(sys.stdin.read()) - db_key = service_key_find("postgresql", data["services"]) - auth_key = service_key_find("authentik", data["services"]) - monitoring_key = service_key_find("gatus", data["services"]) + services = data["services"] + hosts = data["hosts"] + + db_key = service_key_find("postgresql", services, hosts) + auth_key = service_key_find("authentik", services, hosts) + monitoring_key = service_key_find("gatus", services, hosts) jinja_loader = jinja2.FileSystemLoader(searchpath="./templates") jinja_env = jinja2.Environment(loader=jinja_loader) template = jinja_env.get_template("infrastructure.d2.j2") - text = template.render( + print(template.render( grid_svcs=[db_key, auth_key], - svcs=parse_services(data["services"]), - hosts=parse_hosts(data["hosts"]), + svcs=parse_services(services, hosts), + hosts=parse_hosts(hosts), db_key=db_key, auth_key=auth_key, monitoring_key=monitoring_key, - ) - print(text) + ))