Skip to content

Commit

Permalink
feat: add optional variable service_directory_namespace and use dynam…
Browse files Browse the repository at this point in the history
…ic block
  • Loading branch information
sanadhis committed Feb 20, 2024
1 parent 7a7eaf6 commit e12768e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
3 changes: 2 additions & 1 deletion modules/private-service-connect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ If you have a firewall rule blocking egress traffic, you will need to configure
| private\_service\_connect\_ip | The internal IP to be used for the private service connect. | `string` | n/a | yes |
| private\_service\_connect\_name | Private Service Connect endpoint name. Defaults to `global-psconnect-ip` | `string` | `"global-psconnect-ip"` | no |
| project\_id | Project ID for Private Service Connect. | `string` | n/a | yes |
| project\_region | Project Region for Private Service Connect. | `string` | "us-central1" | yes |
| service\_directory\_namespace | Service Directory namespace to register the forwarding rule under. | `string` | "" | no |
| service\_directory\_region | Service Directory region to register this global forwarding rule under. Defaults to `us-central1` if not defined. | `string` | "" | no |

## Outputs

Expand Down
10 changes: 8 additions & 2 deletions modules/private-service-connect/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
18 changes: 12 additions & 6 deletions modules/private-service-connect/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = ""
}

0 comments on commit e12768e

Please sign in to comment.