diff --git a/modules/subnets-beta/main.tf b/modules/subnets-beta/main.tf index d02cd4b0..c35f4a49 100644 --- a/modules/subnets-beta/main.tf +++ b/modules/subnets-beta/main.tf @@ -52,16 +52,14 @@ resource "google_compute_subnetwork" "subnetwork" { network = var.network_name project = var.project_id description = lookup(each.value, "description", null) - secondary_ip_range = [ - for i in range( - length( - contains( - keys(var.secondary_ranges), each.value.subnet_name) == true - ? var.secondary_ranges[each.value.subnet_name] - : [] - )) : - var.secondary_ranges[each.value.subnet_name][i] - ] + dynamic "secondary_ip_range" { + for_each = contains(keys(var.secondary_ranges), each.value.subnet_name) == true ? var.secondary_ranges[each.value.subnet_name] : [] + + content { + range_name = secondary_ip_range.value.range_name + ip_cidr_range = secondary_ip_range.value.ip_cidr_range + } + } purpose = lookup(each.value, "purpose", null) role = lookup(each.value, "role", null) diff --git a/modules/subnets/main.tf b/modules/subnets/main.tf index da0102d6..01aea2f6 100644 --- a/modules/subnets/main.tf +++ b/modules/subnets/main.tf @@ -52,16 +52,14 @@ resource "google_compute_subnetwork" "subnetwork" { network = var.network_name project = var.project_id description = lookup(each.value, "description", null) - secondary_ip_range = [ - for i in range( - length( - contains( - keys(var.secondary_ranges), each.value.subnet_name) == true - ? var.secondary_ranges[each.value.subnet_name] - : [] - )) : - var.secondary_ranges[each.value.subnet_name][i] - ] + dynamic "secondary_ip_range" { + for_each = contains(keys(var.secondary_ranges), each.value.subnet_name) == true ? var.secondary_ranges[each.value.subnet_name] : [] + + content { + range_name = secondary_ip_range.value.range_name + ip_cidr_range = secondary_ip_range.value.ip_cidr_range + } + } purpose = lookup(each.value, "purpose", null) role = lookup(each.value, "role", null)