From 2adc566aa37d564e9b87b3183cb8195b5fa11958 Mon Sep 17 00:00:00 2001 From: Julliano Goncalves Date: Mon, 25 Dec 2023 01:02:35 -0300 Subject: [PATCH] feat!: Add dynamic block to define secondary subnets (#523) Signed-off-by: Julliano Goncalves Co-authored-by: Imran Nayer Co-authored-by: Andrew Peabody --- modules/subnets-beta/main.tf | 18 ++++++++---------- modules/subnets/main.tf | 18 ++++++++---------- 2 files changed, 16 insertions(+), 20 deletions(-) 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)