From 810bf9acb5df5ea58205e166412972ce870013de Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Sat, 19 Oct 2024 00:19:23 +0200 Subject: [PATCH] Refactor "dns" to remove target-domain split --- modules/infrastructure/variables.tf | 1 - modules/services/authentik.tf | 2 +- modules/services/variables.tf | 1 - playbooks/filter_plugins/gatus.py | 6 +- playbooks/filter_plugins/service_filters.py | 6 +- services.auto.tfvars | 82 +++++++-------------- variables.tf | 1 - visualize.py | 6 +- 8 files changed, 33 insertions(+), 72 deletions(-) diff --git a/modules/infrastructure/variables.tf b/modules/infrastructure/variables.tf index f6707be..5396a3b 100644 --- a/modules/infrastructure/variables.tf +++ b/modules/infrastructure/variables.tf @@ -16,7 +16,6 @@ variable "services" { host = string dns = optional(list(object({ domain = string - target = string name = optional(string) alias = optional(string) }))) diff --git a/modules/services/authentik.tf b/modules/services/authentik.tf index ea784c4..cf9cd2b 100644 --- a/modules/services/authentik.tf +++ b/modules/services/authentik.tf @@ -70,6 +70,6 @@ resource "authentik_provider_oauth2" "service_providers" { resource "authentik_application" "service_applications" { for_each = local.services_auth name = each.value.name - slug = "${each.value.dns[0].target}-serguzim-me" + slug = replace(each.value.dns[0].domain, ".", "-") protocol_provider = authentik_provider_oauth2.service_providers[each.key].id } diff --git a/modules/services/variables.tf b/modules/services/variables.tf index 1829584..a5b866a 100644 --- a/modules/services/variables.tf +++ b/modules/services/variables.tf @@ -7,7 +7,6 @@ variable "services" { host = string dns = optional(list(object({ domain = string - target = string name = optional(string) alias = optional(string) }))) diff --git a/playbooks/filter_plugins/gatus.py b/playbooks/filter_plugins/gatus.py index aa9ef3b..3d3a347 100644 --- a/playbooks/filter_plugins/gatus.py +++ b/playbooks/filter_plugins/gatus.py @@ -53,11 +53,7 @@ class FilterModule(object): for service in services: if mon := service.get("monitoring"): if service.get("dns"): - dns = service["dns"][0] - url = "https://" - if dns.get("target") != "@": - url += f"{dns["target"]}." - url += dns['domain'] + url = f"https://{service["dns"][0]['domain']}" if mon_url := mon.get("url"): if mon_url.startswith("/"): diff --git a/playbooks/filter_plugins/service_filters.py b/playbooks/filter_plugins/service_filters.py index 1ff7896..9a91455 100644 --- a/playbooks/filter_plugins/service_filters.py +++ b/playbooks/filter_plugins/service_filters.py @@ -38,9 +38,11 @@ class FilterModule(object): for service in services: for dns in service.get("dns") or []: name = dns.get("name") or service["name"] + domain_parts = dns["domain"].split(".") + target_parts = domain_parts[:-2] or ["@"] result[name] = { - "target": dns["target"], - "domain": dns["domain"], + "target": ".".join(target_parts), + "domain": ".".join(domain_parts[-2:]), } if dns.get("alias"): diff --git a/services.auto.tfvars b/services.auto.tfvars index 2fa660b..a4a0939 100644 --- a/services.auto.tfvars +++ b/services.auto.tfvars @@ -3,8 +3,7 @@ services = { name = "acme_dns" host = "node001" dns = [{ - domain = "serguzim.me" - target = "acme" + domain = "acme.serguzim.me" }] monitoring = { url = "/health" @@ -19,8 +18,7 @@ services = { name = "authentik" host = "node003" dns = [{ - domain = "serguzim.me" - target = "auth" + domain = "auth.serguzim.me" }] monitoring = { url = "/-/health/live/" @@ -45,18 +43,15 @@ services = { host = "node002" dns = [ { - domain = "serguzim.me" - target = "faas" + domain = "faas.serguzim.me" }, { domain = "serguzim.me" - target = "@" name = "webpage-serguzim" alias = "faas" }, { - domain = "serguzim.me" - target = "www" + domain = "www.serguzim.me" name = "webpage-serguzim-www" alias = "webpage-serguzim" } @@ -74,8 +69,7 @@ services = { name = "forgejo" host = "node003" dns = [{ - domain = "serguzim.me" - target = "git" + domain = "git.serguzim.me" }] backup = [{ name = "forgejo_data" @@ -111,8 +105,7 @@ services = { name = "gatus" host = "node003" dns = [{ - domain = "serguzim.me" - target = "status" + domain = "status.serguzim.me" }] backup = [{ name = "gatus_data" @@ -128,8 +121,7 @@ services = { name = "homebox" host = "node003" dns = [{ - domain = "serguzim.me" - target = "inventory" + domain = "inventory.serguzim.me" }] backup = [{ name = "homebox_data" @@ -152,8 +144,7 @@ services = { name = "immich" host = "node002" dns = [{ - domain = "serguzim.me" - target = "gallery" + domain = "gallery.serguzim.me" }] backup = [ { @@ -178,8 +169,7 @@ services = { name = "influxdb" host = "node002" dns = [{ - domain = "serguzim.me" - target = "tick" + domain = "tick.serguzim.me" }] backup = [{ name = "influxdb_data" @@ -202,8 +192,7 @@ services = { name = "jellyfin" host = "node002" dns = [{ - domain = "serguzim.me" - target = "media" + domain = "media.serguzim.me" }] backup = [{ name = "jellyfin_config" @@ -226,8 +215,7 @@ services = { name = "linkwarden" host = "node003" dns = [{ - domain = "serguzim.me" - target = "bookmarks" + domain = "bookmarks.serguzim.me" }] monitoring = { url = "/api/v1/logins" @@ -244,8 +232,7 @@ services = { name = "mailcowdockerized" host = "node003" dns = [{ - domain = "serguzim.me" - target = "mail" + domain = "mail.serguzim.me" }] backup = [{ name = "mailcowdockerized" @@ -264,12 +251,10 @@ services = { host = "node002" dns = [ { - domain = "serguzim.me" - target = "s3" + domain = "s3.serguzim.me" }, { - domain = "serguzim.me" - target = "console.s3" + domain = "s3.serguzim.me" name = "minio-console" alias = "minio" } @@ -292,8 +277,7 @@ services = { name = "ntfy" host = "node003" dns = [{ - domain = "serguzim.me" - target = "push" + domain = "push.serguzim.me" }] backup = [{ name = "ntfy_data" @@ -338,11 +322,9 @@ services = { dns = [ { domain = "reitanlage-oranienburg.de" - target = "@" }, { - domain = "reitanlage-oranienburg.de" - target = "www" + domain = "www.reitanlage-oranienburg.de" name = "reitanlage_oranienburg-www" alias = "reitanlage_oranienburg" } @@ -365,11 +347,9 @@ services = { dns = [ { domain = "msrg.cc" - target = "@" }, { domain = "msvg.cc" - target = "@" name = "shlink-msvg" alias = "shlink" } @@ -392,12 +372,10 @@ services = { host = "node003" dns = [ { - domain = "serguzim.me" - target = "matrix" + domain = "matrix.serguzim.me" }, { - domain = "msrg.cc" - target = "matrix" + domain = "matrix.msrg.cc" name = "synapse-msrg" alias = "synapse" } @@ -421,8 +399,7 @@ services = { name = "tandoor" host = "node003" dns = [{ - domain = "serguzim.me" - target = "recipes" + domain = "recipes.serguzim.me" }] backup = [{ name = "tandoor_mediafiles" @@ -442,12 +419,10 @@ services = { host = "node003" dns = [ { - domain = "serguzim.me" - target = "ts" + domain = "ts.serguzim.me" }, { - domain = "serguzim.me" - target = "hook" + domain = "hook.serguzim.me" name = "teamspeak_fallback-hook" alias = "teamspeak_fallback" } @@ -476,8 +451,7 @@ services = { name = "tinytinyrss" host = "node001" dns = [{ - domain = "serguzim.me" - target = "rss" + domain = "rss.serguzim.me" }] monitoring = { url = "/tt-rss/" @@ -492,8 +466,7 @@ services = { name = "umami" host = "node001" dns = [{ - domain = "serguzim.me" - target = "analytics" + domain = "analytics.serguzim.me" }] monitoring = { url = "/api/heartbeat" @@ -508,8 +481,7 @@ services = { name = "vikunja" host = "node003" dns = [{ - domain = "serguzim.me" - target = "todo" + domain = "todo.serguzim.me" }] backup = [{ name = "vikunja_data" @@ -529,8 +501,7 @@ services = { name = "wiki_js" host = "node001" dns = [{ - domain = "serguzim.me" - target = "wiki" + domain = "wiki.serguzim.me" }] monitoring = { group = "4-services" @@ -545,8 +516,7 @@ services = { name = "woodpecker" host = "node003" dns = [{ - domain = "serguzim.me" - target = "ci" + domain = "ci.serguzim.me" }] monitoring = { url = "/healthz" diff --git a/variables.tf b/variables.tf index 735eb9e..9aa52d8 100644 --- a/variables.tf +++ b/variables.tf @@ -133,7 +133,6 @@ variable "services" { host = string dns = optional(list(object({ domain = string - target = string name = optional(string) alias = optional(string) }))) diff --git a/visualize.py b/visualize.py index e1f2dae..8b1c94d 100755 --- a/visualize.py +++ b/visualize.py @@ -63,11 +63,7 @@ def parse_services(services, hosts): domains = [] for dns in data.get("dns") or []: - domain = "" - if dns.get("target") != "@": - domain += f"{dns["target"]}." - domain += dns['domain'] - domains.append(f"- {domain}") + domains.append(f"- {dns['domain']}") data['key'] = svc_key data['label'] = "\\n".join([svc] + domains)