ingress/terraform/dns.tf

71 lines
1.5 KiB
Terraform
Raw Normal View History

2024-09-17 19:22:50 +00:00
locals {
nodes_for_dns = { for k, v in var.nodes : k => v if v.public != null && v.internal != null }
}
2024-08-23 20:03:47 +00:00
data "digitalocean_domain" "ingress" {
name = "ingress.tjo.cloud"
}
resource "digitalocean_record" "public" {
for_each = merge(
{
2024-09-17 19:22:50 +00:00
for key, node in local.nodes_for_dns : key => {
2024-08-23 20:03:47 +00:00
node = node.name,
2024-09-17 19:22:50 +00:00
ip = node.public.ipv4,
2024-08-23 20:03:47 +00:00
type = "A",
}
},
{
2024-09-17 19:22:50 +00:00
for key, node in local.nodes_for_dns : key => {
2024-08-23 20:03:47 +00:00
node = node.name,
2024-09-17 19:22:50 +00:00
ip = node.public.ipv6,
2024-08-23 20:03:47 +00:00
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(
{
2024-09-17 19:22:50 +00:00
for key, node in local.nodes_for_dns : key => {
2024-08-23 20:03:47 +00:00
node = node.name,
2024-09-17 19:22:50 +00:00
ip = node.internal.ipv4,
2024-08-23 20:03:47 +00:00
type = "A",
}
},
{
2024-09-17 19:22:50 +00:00
for key, node in local.nodes_for_dns : key => {
2024-08-23 20:03:47 +00:00
node = node.name,
2024-09-17 19:22:50 +00:00
ip = node.internal.ipv6,
2024-08-23 20:03:47 +00:00
type = "AAAA",
}
}
)
domain = data.digitalocean_domain.ingress.id
type = each.value.type
2024-08-24 10:13:05 +00:00
name = "internal.${lower(each.value.node)}"
2024-08-23 20:03:47 +00:00
value = each.value.ip
ttl = 60
}
2024-08-24 10:13:05 +00:00
resource "digitalocean_record" "srv" {
2024-09-17 19:22:50 +00:00
for_each = local.nodes_for_dns
2024-08-24 10:13:05 +00:00
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
}