Skip to content

Commit d87d315

Browse files
Iakov Noskovcrrlcx
authored andcommitted
Add rule_custom_name variable to PSC endpoints for improved naming flexibility
1 parent cccdb22 commit d87d315

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

modules/psc_forwarding_rule/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ data "google_alloydb_instance" "alloydb_instance" {
3737
resource "google_compute_address" "psc_address" {
3838
for_each = { for idx, config in var.psc_endpoints : idx => config if config.ip_address_literal != null }
3939
project = each.value.endpoint_project_id
40-
name = "psc-compute-address-${each.value.producer_cloudsql != null && each.value.producer_cloudsql.instance_name != null ? each.value.producer_cloudsql.instance_name : (each.value.producer_alloydb != null && each.value.producer_alloydb.instance_name != null ? each.value.producer_alloydb.instance_name : "custom-${each.key}")}"
40+
name = "psc-compute-address-${each.value.producer_cloudsql != null && each.value.producer_cloudsql.instance_name != null ? each.value.producer_cloudsql.instance_name : (each.value.producer_alloydb != null && each.value.producer_alloydb.instance_name != null ? each.value.producer_alloydb.instance_name : "${each.value.rule_custom_name}-${each.key}")}"
4141
region = each.value.region != null ? each.value.region : (each.value.producer_cloudsql != null && each.value.producer_cloudsql.instance_name != null ? data.google_sql_database_instance.cloudsql_instance[each.key].region : (each.value.producer_alloydb != null && each.value.producer_alloydb.instance_name != null ? data.google_alloydb_instance.alloydb_instance[each.key].location : split("/", each.value.target)[3]))
4242
address_type = "INTERNAL"
4343
subnetwork = each.value.subnetwork_name
@@ -47,12 +47,12 @@ resource "google_compute_address" "psc_address" {
4747
resource "google_compute_forwarding_rule" "psc_forwarding_rule" {
4848
for_each = { for idx, config in var.psc_endpoints : idx => config }
4949
project = each.value.endpoint_project_id
50-
name = "psc-forwarding-rule-${each.value.producer_cloudsql != null && each.value.producer_cloudsql.instance_name != null ? each.value.producer_cloudsql.instance_name : (each.value.producer_alloydb != null && each.value.producer_alloydb.instance_name != null ? each.value.producer_alloydb.instance_name : "custom-${each.key}")}"
50+
name = "psc-forwarding-rule-${each.value.producer_cloudsql != null && each.value.producer_cloudsql.instance_name != null ? each.value.producer_cloudsql.instance_name : (each.value.producer_alloydb != null && each.value.producer_alloydb.instance_name != null ? each.value.producer_alloydb.instance_name : "${each.value.rule_custom_name}-${each.key}")}"
5151
region = each.value.region != null ? each.value.region : (each.value.producer_cloudsql != null && each.value.producer_cloudsql.instance_name != null ? data.google_sql_database_instance.cloudsql_instance[each.key].region : (each.value.producer_alloydb != null && each.value.producer_alloydb.instance_name != null ? data.google_alloydb_instance.alloydb_instance[each.key].location : split("/", each.value.target)[3]))
5252
network = each.value.network_name
5353
subnetwork = each.value.subnetwork_name
5454
ip_address = contains(keys(google_compute_address.psc_address), each.key) ? google_compute_address.psc_address[each.key].self_link : null
5555
load_balancing_scheme = ""
5656
allow_psc_global_access = each.value.allow_psc_global_access
5757
target = local.forwarding_rule_targets[each.key]
58-
}
58+
}

modules/psc_forwarding_rule/variables.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ variable "psc_endpoints" {
5757
cluster_id = optional(string)
5858
}), {})
5959

60+
# Rule custom name.
61+
rule_custom_name = optional(string, "custom")
62+
6063
# The target for the forwarding rule.
6164
target = optional(string)
6265
}))
@@ -70,4 +73,4 @@ variable "psc_endpoints" {
7073
])
7174
error_message = "Exactly one of 'producer_cloudsql.instance_name', 'producer_alloydb.instance_name', or 'target' must be specified for each PSC endpoint."
7275
}
73-
}
76+
}

0 commit comments

Comments
 (0)