From 446ea076e8878607215bec488ced5950400a02fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20Niesiob=C4=99dzki?= Date: Sat, 11 May 2024 14:52:23 +0000 Subject: [PATCH] Review fixes --- modules/net-address/README.md | 13 +++++-------- modules/net-address/psc.tf | 9 +++++---- modules/net-address/variables.tf | 18 +++++++----------- tests/collectors.py | 2 +- .../examples/psc-service-attachment.yaml | 1 - 5 files changed, 18 insertions(+), 25 deletions(-) diff --git a/modules/net-address/README.md b/modules/net-address/README.md index a2cc678113..82d89f3d5a 100644 --- a/modules/net-address/README.md +++ b/modules/net-address/README.md @@ -122,20 +122,17 @@ module "addresses" { # tftest modules=1 resources=1 inventory=psc.yaml e2e ``` -To create PSC address targeting a service provide `service_attachment`. +To create PSC address targeting a service regional provider use the `service_attachment` property. ```hcl module "addresses" { source = "./fabric/modules/net-address" project_id = var.project_id psc_addresses = { cloudsql-one = { - address = "10.0.16.32" - subnet_self_link = var.subnet.self_link - region = var.region - service_attachment = { - name = "cloudsql-one" - psc_service_attachment_link = module.cloudsql-instance.psc_service_attachment_link - } + address = "10.0.16.32" + subnet_self_link = var.subnet.self_link + region = var.region + service_attachment = module.cloudsql-instance.psc_service_attachment_link } } } diff --git a/modules/net-address/psc.tf b/modules/net-address/psc.tf index 5b55da1d46..82d694ffb0 100644 --- a/modules/net-address/psc.tf +++ b/modules/net-address/psc.tf @@ -65,12 +65,12 @@ resource "google_compute_global_address" "psc" { resource "google_compute_global_forwarding_rule" "psc_consumer" { for_each = { for name, psc in local.global_psc : name => psc if psc.service_attachment != null } - name = each.value.service_attachment.name + name = each.value.name project = var.project_id subnetwork = each.value.subnet_self_link ip_address = google_compute_global_address.psc[each.key].self_link load_balancing_scheme = "" - target = each.value.service_attachment.psc_service_attachment_link + target = each.value.service_attachment } # regional PSC services @@ -82,6 +82,7 @@ resource "google_compute_address" "psc" { address_type = "INTERNAL" description = each.value.description network = each.value.network + # purpose not applicable for regional address # purpose = "PRIVATE_SERVICE_CONNECT" region = each.value.region subnetwork = each.value.subnet_self_link @@ -90,12 +91,12 @@ resource "google_compute_address" "psc" { resource "google_compute_forwarding_rule" "psc_consumer" { for_each = { for name, psc in local.regional_psc : name => psc if psc.service_attachment != null } - name = each.value.service_attachment.name + name = each.value.name project = var.project_id region = each.value.region subnetwork = each.value.subnet_self_link ip_address = google_compute_address.psc[each.key].self_link load_balancing_scheme = "" recreate_closed_psc = true - target = each.value.service_attachment.psc_service_attachment_link + target = each.value.service_attachment } diff --git a/modules/net-address/variables.tf b/modules/net-address/variables.tf index ae7200d01e..866335c51e 100644 --- a/modules/net-address/variables.tf +++ b/modules/net-address/variables.tf @@ -107,7 +107,6 @@ variable "psa_addresses" { prefix_length = number description = optional(string, "Terraform managed.") name = optional(string) - })) default = {} } @@ -115,16 +114,13 @@ variable "psa_addresses" { variable "psc_addresses" { description = "Map of internal addresses used for Private Service Connect." type = map(object({ - address = string - description = optional(string, "Terraform managed.") - name = optional(string) - network = optional(string) - region = optional(string) # - subnet_self_link = optional(string) - service_attachment = optional(object({ - name = string # forwarding rule name - psc_service_attachment_link = string - })) + address = string + description = optional(string, "Terraform managed.") + name = optional(string) + network = optional(string) + region = optional(string) + subnet_self_link = optional(string) + service_attachment = optional(string) })) default = {} validation { diff --git a/tests/collectors.py b/tests/collectors.py index e6ed006818..310b8151cc 100644 --- a/tests/collectors.py +++ b/tests/collectors.py @@ -92,7 +92,7 @@ def runtest(self): self.tf_var_files, self.extra_files) except AssertionError: def full_paths(x): - return [f'{self.parent.path.parent}/{x}' for x in x] + return [(self.parent.path.parent / x ) for x in x] print(f'Error in inventory file: {" ".join(full_paths(self.inventory))}') print(f'To regenerate inventory run: python tools/plan_summary.py {self.module} {" ".join(full_paths(self.tf_var_files))}') raise diff --git a/tests/modules/net_address/examples/psc-service-attachment.yaml b/tests/modules/net_address/examples/psc-service-attachment.yaml index a5f6c6e944..7c3eaca02a 100644 --- a/tests/modules/net_address/examples/psc-service-attachment.yaml +++ b/tests/modules/net_address/examples/psc-service-attachment.yaml @@ -27,4 +27,3 @@ values: name: cloudsql-one project: project-id subnetwork: subnet_self_link - \ No newline at end of file