Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wiktorn committed May 11, 2024
1 parent d72254b commit 446ea07
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 25 deletions.
13 changes: 5 additions & 8 deletions modules/net-address/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions modules/net-address/psc.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
18 changes: 7 additions & 11 deletions modules/net-address/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,20 @@ variable "psa_addresses" {
prefix_length = number
description = optional(string, "Terraform managed.")
name = optional(string)

}))
default = {}
}

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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ values:
name: cloudsql-one
project: project-id
subnetwork: subnet_self_link

0 comments on commit 446ea07

Please sign in to comment.