chore: refined control script
This commit is contained in:
@@ -14,15 +14,29 @@ resource "hcloud_zone" "this" {
|
||||
}
|
||||
}
|
||||
|
||||
resource "hcloud_zone_rrset" "a" {
|
||||
for_each = { for r in var.records : "${r.zone}/${r.name}" => r }
|
||||
locals {
|
||||
# Group flat var.records entries by zone/name/type into one set of values
|
||||
# each, since a Hetzner RRSet is keyed on (zone, name, type) and can hold
|
||||
# several values (e.g. an SPF and a google-site-verification TXT both live
|
||||
# under the same "@" TXT RRSet).
|
||||
rrsets = {
|
||||
for key, items in { for r in var.records : "${r.zone}/${r.name}/${r.type}" => r... } : key => {
|
||||
zone = items[0].zone
|
||||
name = items[0].name
|
||||
type = items[0].type
|
||||
ttl = items[0].ttl
|
||||
values = [for i in items : i.value]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "hcloud_zone_rrset" "this" {
|
||||
for_each = local.rrsets
|
||||
|
||||
zone = hcloud_zone.this[each.value.zone].id
|
||||
name = each.value.name
|
||||
type = "A"
|
||||
type = each.value.type
|
||||
ttl = each.value.ttl
|
||||
|
||||
records = [
|
||||
{ value = each.value.value }
|
||||
]
|
||||
records = [for v in each.value.values : { value = v }]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user