fix: use ip address map indexed by server key (#4)
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/build-package Pipeline was successful
ci/woodpecker/tag/test Pipeline was successful
ci/woodpecker/tag/build-package Pipeline was successful

Reviewed-on: #4
Co-authored-by: Robert Kaussow <mail@thegeeklab.de>
Co-committed-by: Robert Kaussow <mail@thegeeklab.de>
This commit is contained in:
Robert Kaussow 2024-03-20 22:45:08 +01:00 committed by Robert Kaussow
parent ad0287e0f3
commit 071b71fa5c
2 changed files with 10 additions and 11 deletions

14
main.tf
View File

@ -1,20 +1,20 @@
locals {
ipv4_addresses = flatten([
for server_key, server in var.server : [
ipv4_addresses = {
for server_key, server in var.server : server.name => flatten([
for k, v in coalescelist(proxmox_virtual_environment_vm.server[server.name].ipv4_addresses, []) :
v if length(regexall("^(lo|docker|veth).*", proxmox_virtual_environment_vm.server[server.name].network_interface_names[k])) == 0
]
])
}
}
locals {
ipv6_addresses = flatten([
for server_key, server in var.server : [
ipv6_addresses = {
for server_key, server in var.server : server.name => flatten([
for k, v in coalescelist(proxmox_virtual_environment_vm.server[server.name].ipv6_addresses, []) :
v if length(regexall("^(lo|docker|veth).*", proxmox_virtual_environment_vm.server[server.name].network_interface_names[k])) == 0
]
])
}
}
resource "proxmox_virtual_environment_vm" "server" {
for_each = { for row in var.server : row.name => row }
@ -113,7 +113,7 @@ resource "restapi_object" "ucs_server" {
"position" : var.ucs_zones[try(each.value.dns_zone, var.server_dns_zone)],
"properties" : {
"name" : each.value.name,
"a" : concat(local.ipv4_addresses, local.ipv6_addresses),
"a" : concat(local.ipv4_addresses[each.key]),
}
})
}

View File

@ -2,8 +2,7 @@ output "output" {
value = {
for server_key, server in proxmox_virtual_environment_vm.server : server_key => merge(
server,
{ ipv4_addresses = local.ipv4_addresses },
{ ipv6_addresses = local.ipv6_addresses }
{ ipv4_addresses = local.ipv4_addresses[server_key] },
)
}
}