75 lines
2 KiB
Terraform
75 lines
2 KiB
Terraform
|
locals {
|
||
|
contabo_hosts = {for key, val in var.hosts : key => val if val.provider == "contabo"}
|
||
|
server_addresses = flatten([
|
||
|
[
|
||
|
for host in local.contabo_hosts : [
|
||
|
{
|
||
|
hostname = host.hostname
|
||
|
ipv4_address = host.ipv4_address
|
||
|
ipv6_address = host.ipv6_address
|
||
|
},
|
||
|
]
|
||
|
],
|
||
|
[
|
||
|
for host in hcloud_server.nodes : [
|
||
|
{
|
||
|
hostname = host.name
|
||
|
ipv4_address = host.ipv4_address
|
||
|
ipv6_address = host.ipv6_address
|
||
|
},
|
||
|
]
|
||
|
]
|
||
|
])
|
||
|
|
||
|
server_addresses_separated = flatten([
|
||
|
for host in local.server_addresses : [
|
||
|
{
|
||
|
hostname = host.hostname
|
||
|
key = "${host.hostname}:ipv4"
|
||
|
address = host.ipv4_address
|
||
|
},
|
||
|
{
|
||
|
hostname = host.hostname
|
||
|
key = "${host.hostname}:ipv6"
|
||
|
address = host.ipv6_address
|
||
|
},
|
||
|
]
|
||
|
])
|
||
|
|
||
|
tailscale_host_addresses = flatten([
|
||
|
for host in data.tailscale_devices.nodes.devices : [
|
||
|
for index, address in host.addresses : {
|
||
|
hostname = host.hostname
|
||
|
key = "${host.hostname}:${index}"
|
||
|
address = address
|
||
|
}
|
||
|
]
|
||
|
])
|
||
|
}
|
||
|
|
||
|
resource "ovh_domain_zone_record" "server_records" {
|
||
|
for_each = { for entry in local.server_addresses_separated: entry.key => entry }
|
||
|
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 = { for entry in local.tailscale_host_addresses: entry.key => entry }
|
||
|
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."
|
||
|
}
|