locals { nodes_for_dns = { for k, v in var.nodes : k => v if v.public != null && v.internal != null } } data "digitalocean_domain" "ingress" { name = "ingress.tjo.cloud" } resource "digitalocean_record" "public" { for_each = merge( { for key, node in local.nodes_for_dns : key => { node = node.name, ip = node.public.ipv4, type = "A", } }, { for key, node in local.nodes_for_dns : key => { node = node.name, ip = node.public.ipv6, type = "AAAA", } } ) domain = data.digitalocean_domain.ingress.id type = each.value.type name = lower(each.value.node) value = each.value.ip ttl = 60 } resource "digitalocean_record" "internal" { for_each = merge( { for key, node in local.nodes_for_dns : key => { node = node.name, ip = node.internal.ipv4, type = "A", } }, { for key, node in local.nodes_for_dns : key => { node = node.name, ip = node.internal.ipv6, type = "AAAA", } } ) domain = data.digitalocean_domain.ingress.id type = each.value.type name = "internal.${lower(each.value.node)}" value = each.value.ip ttl = 60 } resource "digitalocean_record" "srv" { for_each = local.nodes_for_dns domain = data.digitalocean_domain.ingress.id type = "SRV" name = digitalocean_record.internal[each.key].fqdn value = "_nginx._tcp" port = 9000 priority = 10 weight = 100 ttl = 60 }