From 5007c1a85ec6a0968dc7a64650160521bc5af507 Mon Sep 17 00:00:00 2001
From: Evangelos Foutras <evangelos@foutrelis.com>
Date: Mon, 16 May 2022 14:18:55 +0300
Subject: [PATCH] tf-stage1: allow setting the NS TTL of geo domains

When adding a new geo domain or doing other testing, we would want to
use a low TTL to allow for making quick changes to the configuration.
---
 tf-stage1/archlinux.tf | 5 +++++
 tf-stage1/templates.tf | 6 +++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/tf-stage1/archlinux.tf b/tf-stage1/archlinux.tf
index e336ed0ec..41bba840f 100644
--- a/tf-stage1/archlinux.tf
+++ b/tf-stage1/archlinux.tf
@@ -366,6 +366,11 @@ locals {
   }
 
   # Domains served by machines in the geo_mirrors group
+  # Valid parameters are:
+  #   - zone_id (mandatory, either of hetznerdns_zone.{archlinux,pkgbuild}.id)
+  #   - name (mandatory, specifies the subdomain to create in the above zone)
+  #   - ttl (optional, the TTL of the NS records, defaults to 86400 if unset)
+  #
   geo_domains = {
     "geo.mirror.pkgbuild.com" = {
       zone_id = hetznerdns_zone.pkgbuild.id
diff --git a/tf-stage1/templates.tf b/tf-stage1/templates.tf
index 24df54627..3fa0888ac 100644
--- a/tf-stage1/templates.tf
+++ b/tf-stage1/templates.tf
@@ -150,7 +150,7 @@ resource "hetznerdns_record" "geo_ns1" {
   name    = each.value.name
   value   = "asia.mirror.pkgbuild.com."
   type    = "NS"
-  ttl     = 86400
+  ttl     = lookup(local.geo_domains[each.key], "ttl", 86400)
 }
 
 resource "hetznerdns_record" "geo_ns2" {
@@ -160,7 +160,7 @@ resource "hetznerdns_record" "geo_ns2" {
   name    = each.value.name
   value   = "america.mirror.pkgbuild.com."
   type    = "NS"
-  ttl     = 86400
+  ttl     = lookup(local.geo_domains[each.key], "ttl", 86400)
 }
 
 resource "hetznerdns_record" "geo_ns3" {
@@ -170,5 +170,5 @@ resource "hetznerdns_record" "geo_ns3" {
   name    = each.value.name
   value   = "europe.mirror.pkgbuild.com."
   type    = "NS"
-  ttl     = 86400
+  ttl     = lookup(local.geo_domains[each.key], "ttl", 86400)
 }
-- 
GitLab