From 8acc60e3280bdb259c78007f947d09dab4b2600d Mon Sep 17 00:00:00 2001 From: "Janik H." Date: Tue, 24 Sep 2024 00:25:58 +0200 Subject: [PATCH] feat(dns): migrate functions from gandi to dnsimple --- terraform/dnsimple.nix | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/terraform/dnsimple.nix b/terraform/dnsimple.nix index eab5ac0..3d2cb36 100644 --- a/terraform/dnsimple.nix +++ b/terraform/dnsimple.nix @@ -45,5 +45,47 @@ in resource.dnsimple_zone.vzfdfp_de = { name = "vzfdfp.de"; }; + + resource.dnsimple_zone_record = let + # https://registry.terraform.io/providers/dnsimple/dnsimple/latest/docs/resources/zone_record + canonicalName = zoneName: record: let + # TODO: make less fragile and have actual unique and stable names + normalize = builtins.replaceStrings ["." "@"] ["_" "_root_"]; + zone = normalize zoneName; + name = normalize record.name; + in "${zone}_${record.type}_${name}"; + + record = name: ttl: type: value: { + inherit name ttl type value; + }; + + proxyRecords = name: ttl: type: value: [ + # kurisu.lahfa.xyz running a sniproxy: + (record name ttl "A" "163.172.69.160") + (record name ttl type value) + ]; + + # Creates a extra *.p record pointing to the sniproxy + dualProxyRecords = name: ttl: type: value: lib.flatten [ + (record name ttl type value) + (proxyRecords "${name}.p" ttl type value) + ]; + + domain = zoneName: records: + builtins.listToAttrs (map (record: { + name = canonicalName zoneName record; + value = record // { + zone_name = zoneName; + }; + } + ) (lib.flatten records)); + zones = domains: lib.zipAttrs (lib.mapAttrsToList (zoneName: records: domain zoneName records) domains); + in zones { + "flowery.systems" = [ + (record "" 300 "CNAME" "news.forkos.org") + ]; + "vzfdfp.de" = [ + ]; + }; }; }