From 38dc22928800ae0955563fe2225b7a8a9c381871 Mon Sep 17 00:00:00 2001 From: Frederik Schwan Date: Sun, 24 Jan 2021 16:18:19 +0100 Subject: [PATCH] improve terraform handling of virtual machine domains machine.domain has been an mandatory attribute which creates .archlinux.org entries automagically. For migrations this can be a problem if .archlinux.org supposed to point to a different machine. Adding the new machine with the same domain leads to additional DNS entries. The DNS ends up pointing to both machines in this case. By making the domain attribute optional for machines, we allow the new machines to be created without any domain pointing to them. --- tf-stage1/archlinux.tf | 3 +-- tf-stage1/templates.tf | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tf-stage1/archlinux.tf b/tf-stage1/archlinux.tf index cd4eb28a..836cd9bb 100644 --- a/tf-stage1/archlinux.tf +++ b/tf-stage1/archlinux.tf @@ -36,7 +36,7 @@ locals { # # Valid parameters are: # - server_type (mandatory) - # - domain (mandatory) + # - domain (optional, creates dns entry .archlinux.org pointing to the machine) # - ttl (optional, applies to the dns entries) # - zone (optionel, required for pkgbuild.com machines) # @@ -81,7 +81,6 @@ locals { } "lists.archlinux.org" = { server_type = "cx11" - domain = "lists" } "mail.archlinux.org" = { server_type = "cx11" diff --git a/tf-stage1/templates.tf b/tf-stage1/templates.tf index 4c2701b2..19ef3a8b 100644 --- a/tf-stage1/templates.tf +++ b/tf-stage1/templates.tf @@ -116,7 +116,9 @@ resource "hcloud_server" "machine" { } resource "hetznerdns_record" "machine_a" { - for_each = local.machines + for_each = { + for name, machine in local.machines : name => machine if can(machine.domain) + } zone_id = lookup(local.machines[each.key], "zone", hetznerdns_zone.archlinux.id) name = each.value.domain @@ -126,7 +128,9 @@ resource "hetznerdns_record" "machine_a" { } resource "hetznerdns_record" "machine_aaaa" { - for_each = local.machines + for_each = { + for name, machine in local.machines : name => machine if can(machine.domain) + } zone_id = lookup(local.machines[each.key], "zone", hetznerdns_zone.archlinux.id) name = each.value.domain