Skip to content

Commit

Permalink
Change all count into for_each
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Schiborr committed Oct 2, 2024
1 parent e856892 commit fa1b855
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
6 changes: 3 additions & 3 deletions modules/ionos-nlb-for-servicecenter/data.tf
Original file line number Diff line number Diff line change
@@ -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
}
20 changes: 10 additions & 10 deletions modules/ionos-nlb-for-servicecenter/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions modules/ionos-nlb-for-servicecenter/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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) <crossconnectsname>: <nlb listener ip>"
}

variable "crossconnects" {
type = list(string)
description = "List of crossconnects which should connect to backend haproxy"
}


0 comments on commit fa1b855

Please sign in to comment.