infrastructure/modules/infrastructure/ovh.tf

73 lines
1.9 KiB
HCL

locals {
server_addresses = flatten([
[
for key, host in contabo_instance.nodes : [
{
key = key
hostname = host.display_name
ipv4_address = host.ip_config[0].v4[0].ip
ipv6_address = host.ip_config[0].v6[0].ip
},
]
],
[
for key, host in hcloud_server.nodes : [
{
key = key
hostname = host.name
ipv4_address = host.ipv4_address
ipv6_address = host.ipv6_address
},
]
]
])
server_addresses_separated = merge([
for host in local.server_addresses : {
"${host.key}:ipv4" = {
hostname = host.hostname
address = host.ipv4_address
},
"${host.key}:ipv6" = {
hostname = host.hostname
address = host.ipv6_address
},
}
]...)
tailscale_host_addresses_separated = merge([
for host in data.tailscale_devices.nodes.devices : {
for address in host.addresses :
"${host.hostname}:${strcontains(address, ":") ? "ipv6" : "ipv4"}" => {
hostname = host.hostname
address = address
}
}
]...)
}
resource "ovh_domain_zone_record" "server_records" {
for_each = local.server_addresses_separated
zone = "serguzim.net"
subdomain = each.value.hostname
fieldtype = strcontains(each.value.address, ":") ? "AAAA" : "A"
ttl = 3600
target = each.value.address
}
resource "ovh_domain_zone_record" "tailscale_vpn" {
for_each = local.tailscale_host_addresses_separated
zone = "serguzim.net"
subdomain = "${each.value.hostname}.vpn"
fieldtype = strcontains(each.value.address, ":") ? "AAAA" : "A"
ttl = 600
target = each.value.address
}
resource "ovh_domain_zone_record" "status_page_cname" {
zone = "serguzim.net"
subdomain = "status"
fieldtype = "CNAME"
ttl = 3600
target = "status.serguzim.me."
}