Improve first creation of servers
This commit is contained in:
parent
26ef8a0d7d
commit
fa644e6dc9
4 changed files with 49 additions and 24 deletions
|
|
@ -15,12 +15,12 @@ output "hosts" {
|
|||
null
|
||||
)
|
||||
|
||||
ipv4_address_vpn = try(
|
||||
local.tailscale_host_addresses_separated["${key}:ipv4"].address,
|
||||
"ipv4_address_vpn" = try(
|
||||
local.tailscale_host_addresses_ipv4[key],
|
||||
null
|
||||
)
|
||||
ipv6_address_vpn = try(
|
||||
local.tailscale_host_addresses_separated["${key}:ipv6"].address,
|
||||
"ipv6_address_vpn" = try(
|
||||
local.tailscale_host_addresses_ipv6[key],
|
||||
null
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,13 +23,23 @@ locals {
|
|||
}
|
||||
]...)
|
||||
|
||||
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
|
||||
}
|
||||
tailscale_host_addresses_ipv4 = merge([
|
||||
for host, _ in var.hosts : {
|
||||
"${host}" = [
|
||||
for address in data.tailscale_device.nodes[host].addresses :
|
||||
address
|
||||
if !strcontains(address, ":")
|
||||
][0]
|
||||
}
|
||||
]...)
|
||||
|
||||
tailscale_host_addresses_ipv6 = merge([
|
||||
for host, _ in var.hosts : {
|
||||
"${host}" = [
|
||||
for address in data.tailscale_device.nodes[host].addresses :
|
||||
address
|
||||
if strcontains(address, ":")
|
||||
][0]
|
||||
}
|
||||
]...)
|
||||
}
|
||||
|
|
@ -43,13 +53,22 @@ resource "ovh_domain_zone_record" "server_records" {
|
|||
target = each.value.address
|
||||
}
|
||||
|
||||
resource "ovh_domain_zone_record" "tailscale_vpn" {
|
||||
for_each = local.tailscale_host_addresses_separated
|
||||
resource "ovh_domain_zone_record" "tailscale_vpn_ipv4" {
|
||||
for_each = local.tailscale_host_addresses_ipv4
|
||||
zone = "serguzim.net"
|
||||
subdomain = "${each.value.hostname}.vpn"
|
||||
fieldtype = strcontains(each.value.address, ":") ? "AAAA" : "A"
|
||||
subdomain = "${each.key}.vpn"
|
||||
fieldtype = "A"
|
||||
ttl = 600
|
||||
target = each.value.address
|
||||
target = each.value
|
||||
}
|
||||
|
||||
resource "ovh_domain_zone_record" "tailscale_vpn_ipv6" {
|
||||
for_each = local.tailscale_host_addresses_ipv6
|
||||
zone = "serguzim.net"
|
||||
subdomain = "${each.key}.vpn"
|
||||
fieldtype = "AAAA"
|
||||
ttl = 600
|
||||
target = each.value
|
||||
}
|
||||
|
||||
resource "ovh_domain_zone_record" "gpg_verify" {
|
||||
|
|
|
|||
|
|
@ -6,12 +6,15 @@ resource "tailscale_tailnet_key" "cloud_init_key" {
|
|||
description = "Cloud-init key used by opentofu"
|
||||
}
|
||||
|
||||
data "tailscale_devices" "nodes" {
|
||||
name_prefix = "node"
|
||||
resource "time_sleep" "wait_for_hosts" {
|
||||
for_each = var.hosts
|
||||
depends_on = [hcloud_server.nodes]
|
||||
create_duration = "60s"
|
||||
}
|
||||
|
||||
locals {
|
||||
tailscale_devices = {
|
||||
for host in data.tailscale_devices.nodes.devices : host.hostname => host
|
||||
}
|
||||
data "tailscale_device" "nodes" {
|
||||
for_each = var.hosts
|
||||
depends_on = [time_sleep.wait_for_hosts]
|
||||
hostname = each.value.hostname
|
||||
wait_for = "60s"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue