diff --git a/modules/ionos-nlb-for-servicecenter/data.tf b/modules/ionos-nlb-for-servicecenter/data.tf index db53c5b..d4870c0 100644 --- a/modules/ionos-nlb-for-servicecenter/data.tf +++ b/modules/ionos-nlb-for-servicecenter/data.tf @@ -1,4 +1,4 @@ data "ionoscloud_private_crossconnect" "crossconnect" { - count = length(var.crossconnects) - name = var.crossconnects[count.index] -} + for_each = var.crossconnects_nlb + name = each.key +} \ No newline at end of file diff --git a/modules/ionos-nlb-for-servicecenter/main.tf b/modules/ionos-nlb-for-servicecenter/main.tf index 8552521..22afcfc 100644 --- a/modules/ionos-nlb-for-servicecenter/main.tf +++ b/modules/ionos-nlb-for-servicecenter/main.tf @@ -6,33 +6,33 @@ module "conventions_coordinates" { } resource "ionoscloud_lan" "crossconnect_lan" { - count = length(var.crossconnects) + for_each = var.crossconnects_nlb datacenter_id = var.datacenter_id - name = "${data.ionoscloud_private_crossconnect.crossconnect[count.index].name}-lan" + name = "${data.ionoscloud_private_crossconnect.crossconnect[each.key].name}-lan" public = false - pcc = data.ionoscloud_private_crossconnect.crossconnect[count.index].id + pcc = data.ionoscloud_private_crossconnect.crossconnect[each.key].id depends_on = [ data.ionoscloud_private_crossconnect.crossconnect ] } resource "ionoscloud_networkloadbalancer" "nlb" { - count = length(var.crossconnects) + for_each = var.crossconnects_nlb datacenter_id = var.datacenter_id - name = "${module.conventions_coordinates.global_identifier}-nlb-${count.index}" - listener_lan = ionoscloud_lan.crossconnect_lan[count.index].id - ips = [var.listener_ips[count.index]] + name = "${each.key}-nlb" + listener_lan = ionoscloud_lan.crossconnect_lan[each.key].id + ips = [each.value] target_lan = var.nlb_target_lan_id } resource "ionoscloud_networkloadbalancer_forwardingrule" "forward_k8" { - count = length(var.crossconnects) + for_each = var.crossconnects_nlb datacenter_id = var.datacenter_id - networkloadbalancer_id = ionoscloud_networkloadbalancer.nlb[count.index].id + networkloadbalancer_id = ionoscloud_networkloadbalancer.nlb[each.key].id name = "forward-logs-and-metrics" algorithm = "ROUND_ROBIN" protocol = "TCP" - listener_ip = var.listener_ips[count.index] + listener_ip = each.value listener_port = var.nlb_listener_port dynamic "targets" { for_each = var.node_nlb_lan_ips diff --git a/modules/ionos-nlb-for-servicecenter/variables.tf b/modules/ionos-nlb-for-servicecenter/variables.tf index 7a7c6ee..61fa892 100644 --- a/modules/ionos-nlb-for-servicecenter/variables.tf +++ b/modules/ionos-nlb-for-servicecenter/variables.tf @@ -53,14 +53,8 @@ variable "nlb_target_health_check_timeout" { default = 6000 } -variable "listener_ips" { - type = list(string) - description = "List of listener ips which should be assigned to nlb listener ip list" +variable "crossconnects_nlb" { + type = map(string) + description = "A map of all crossconnects containing (multiple) : " } -variable "crossconnects" { - type = list(string) - description = "List of crossconnects which should connect to backend haproxy" -} - -