From 022a0ebf054e929c548086687b28ec9ce1c3bf60 Mon Sep 17 00:00:00 2001 From: sanadhis Date: Tue, 20 Feb 2024 19:37:28 +0100 Subject: [PATCH] feat: add optional variable service_directory_namespace and use dynamic block --- modules/private-service-connect/main.tf | 10 ++++++++-- modules/private-service-connect/variables.tf | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/modules/private-service-connect/main.tf b/modules/private-service-connect/main.tf index fb2b4aba8..4b58bea31 100644 --- a/modules/private-service-connect/main.tf +++ b/modules/private-service-connect/main.tf @@ -38,7 +38,13 @@ resource "google_compute_global_forwarding_rule" "forwarding_rule_private_servic network = var.network_self_link ip_address = google_compute_global_address.private_service_connect.id load_balancing_scheme = "" - service_directory_registrations { - service_directory_region = var.project_region + + dynamic "service_directory_registrations" { + for_each = var.service_directory_namespace != "" || var.service_directory_region != "" ? [1] : [] + + content { + service_directory_namespace = var.service_directory_namespace + service_directory_region = var.service_directory_region + } } } diff --git a/modules/private-service-connect/variables.tf b/modules/private-service-connect/variables.tf index 355c2cd29..c4e82181c 100644 --- a/modules/private-service-connect/variables.tf +++ b/modules/private-service-connect/variables.tf @@ -19,12 +19,6 @@ variable "project_id" { type = string } -variable "project_region" { - description = "Project Region for Private Service Connect." - type = string - default = "us-central1" -} - variable "network_self_link" { description = "Network self link for Private Service Connect." type = string @@ -62,3 +56,15 @@ variable "forwarding_rule_target" { error_message = "For forwarding_rule_target only `all-apis` and `vpc-sc` are valid." } } + +variable "service_directory_namespace" { + description = "Service Directory namespace to register the forwarding rule under" + type = string + default = "" +} + +variable "service_directory_region" { + description = "Service Directory region to register this global forwarding rule under. Defaults to `us-central1` if not defined." + type = string + default = "" +}