From 691dbad3a2dcc353f89dab023989f95325ae75dc Mon Sep 17 00:00:00 2001 From: Daniel Andrade Date: Mon, 25 Nov 2024 20:07:49 -0300 Subject: [PATCH] fix: fail gracefully if sources index does not exist --- modules/regular_service_perimeter/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/regular_service_perimeter/main.tf b/modules/regular_service_perimeter/main.tf index 2a4b011..e9fb470 100644 --- a/modules/regular_service_perimeter/main.tf +++ b/modules/regular_service_perimeter/main.tf @@ -84,7 +84,7 @@ resource "google_access_context_manager_service_perimeter" "regular_service_peri access_level = sources.value == "access_level" ? sources.key != "*" ? "accessPolicies/${var.policy}/accessLevels/${sources.key}" : "*" : null } } - source_restriction = egress_policies.value["from"]["sources"] != null ? "SOURCE_RESTRICTION_ENABLED" : null + source_restriction = lookup(egress_policies.value["from"], "sources", null) != null ? "SOURCE_RESTRICTION_ENABLED" : null } egress_to { resources = lookup(egress_policies.value["to"], "resources", ["*"]) @@ -179,7 +179,7 @@ resource "google_access_context_manager_service_perimeter" "regular_service_peri access_level = sources.value == "access_level" ? sources.key != "*" ? "accessPolicies/${var.policy}/accessLevels/${sources.key}" : "*" : null } } - source_restriction = egress_policies_dry_run.value["from"]["sources"] != null ? "SOURCE_RESTRICTION_ENABLED" : null + source_restriction = lookup(egress_policies_dry_run.value["from"], "sources", null) != null ? "SOURCE_RESTRICTION_ENABLED" : null } egress_to { resources = lookup(egress_policies_dry_run.value["to"], "resources", ["*"])