From 52339f1f05aa04b64e8b60c6d5c8fa9d49e92076 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sun, 17 Mar 2024 12:05:53 +0100 Subject: [PATCH] fix: add filter to remove loopback and overlay networks from ip lists --- main.tf | 25 +++++++++++++++++++------ outputs.tf | 6 +++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/main.tf b/main.tf index f765990..030782c 100644 --- a/main.tf +++ b/main.tf @@ -1,3 +1,21 @@ +locals { + ipv4_addresses = flatten([ + for server_key, server in var.server : [ + 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 : [ + 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 } @@ -95,12 +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( - [ - for k, v in flatten(coalesce(proxmox_virtual_environment_vm.server[each.value.name].ipv4_addresses, [])) : - v if length(regexall(proxmox_virtual_environment_vm.server[each.value.name].network_interface_names[k], "^(lo|docker).*")) == 0 - ], - ), + "a" : concat(local.ipv4_addresses, local.ipv6_addresses), } }) } diff --git a/outputs.tf b/outputs.tf index ef90176..8645afe 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,5 +1,9 @@ output "output" { value = { - for server_key, server in proxmox_virtual_environment_vm.server : server_key => server + for server_key, server in proxmox_virtual_environment_vm.server : server_key => merge( + server, + { ipv4_addresses = local.ipv4_addresses }, + { ipv6_addresses = local.ipv6_addresses } + ) } } -- 2.45.2