From 634c06e5a1b7d8556d8adb8e86fb398e65c20706 Mon Sep 17 00:00:00 2001 From: norbert-loderer Date: Thu, 14 Aug 2025 07:08:54 +0000 Subject: [PATCH] Add cross project support for backend bucket (#3273) * Added cross project support for backend bucket. * Ran terraform fmt. * Ran tfdoc. --------- Co-authored-by: Ludovico Magnocavallo --- modules/net-lb-app-ext/README.md | 24 ++++++++++++------------ modules/net-lb-app-ext/backends.tf | 8 ++++++-- modules/net-lb-app-ext/variables.tf | 1 + 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/modules/net-lb-app-ext/README.md b/modules/net-lb-app-ext/README.md index dcdb57da3..9a511143b 100644 --- a/modules/net-lb-app-ext/README.md +++ b/modules/net-lb-app-ext/README.md @@ -1062,21 +1062,21 @@ After provisioning this change, and verifying that the new certificate is provis | name | description | type | required | default | |---|---|:---:|:---:|:---:| -| [name](variables.tf#L110) | Load balancer name. | string | ✓ | | -| [project_id](variables.tf#L207) | Project id. | string | ✓ | | -| [backend_buckets_config](variables.tf#L17) | Backend buckets configuration. | map(object({…})) | | {} | +| [name](variables.tf#L111) | Load balancer name. | string | ✓ | | +| [project_id](variables.tf#L208) | Project id. | string | ✓ | | +| [backend_buckets_config](variables.tf#L17) | Backend buckets configuration. | map(object({…})) | | {} | | [backend_service_configs](variables-backend-service.tf#L19) | Backend service level configuration. | map(object({…})) })) | | {} | -| [description](variables.tf#L50) | Optional description used for resources. | string | | "Terraform managed." | -| [forwarding_rules_config](variables.tf#L56) | The optional forwarding rules configuration. | map(object({…})) | | {…} | -| [group_configs](variables.tf#L77) | Optional unmanaged groups to create. Can be referenced in backends via key or outputs. | map(object({…})) | | {} | +| [description](variables.tf#L51) | Optional description used for resources. | string | | "Terraform managed." | +| [forwarding_rules_config](variables.tf#L57) | The optional forwarding rules configuration. | map(object({…})) | | {…} | +| [group_configs](variables.tf#L78) | Optional unmanaged groups to create. Can be referenced in backends via key or outputs. | map(object({…})) | | {} | | [health_check_configs](variables-health-check.tf#L19) | Optional auto-created health check configurations, use the output self-link to set it in the auto healing policy. Refer to examples for usage. | map(object({…})) | | {…} | -| [https_proxy_config](variables.tf#L89) | HTTPS proxy connfiguration. | object({…}) | | {} | -| [labels](variables.tf#L104) | Labels set on resources. | map(string) | | {} | -| [neg_configs](variables.tf#L115) | Optional network endpoint groups to create. Can be referenced in backends via key or outputs. | map(object({…})) | | {} | -| [protocol](variables.tf#L212) | Protocol supported by this load balancer. | string | | "HTTP" | -| [ssl_certificates](variables.tf#L225) | SSL target proxy certificates (only if protocol is HTTPS) for existing, custom, and managed certificates. | object({…}) | | {} | +| [https_proxy_config](variables.tf#L90) | HTTPS proxy connfiguration. | object({…}) | | {} | +| [labels](variables.tf#L105) | Labels set on resources. | map(string) | | {} | +| [neg_configs](variables.tf#L116) | Optional network endpoint groups to create. Can be referenced in backends via key or outputs. | map(object({…})) | | {} | +| [protocol](variables.tf#L213) | Protocol supported by this load balancer. | string | | "HTTP" | +| [ssl_certificates](variables.tf#L226) | SSL target proxy certificates (only if protocol is HTTPS) for existing, custom, and managed certificates. | object({…}) | | {} | | [urlmap_config](variables-urlmap.tf#L19) | The URL map configuration. | object({…}) | | {…} | -| [use_classic_version](variables.tf#L243) | Use classic Global Load Balancer. | bool | | true | +| [use_classic_version](variables.tf#L244) | Use classic Global Load Balancer. | bool | | true | ## Outputs diff --git a/modules/net-lb-app-ext/backends.tf b/modules/net-lb-app-ext/backends.tf index 107e2be65..a025aa423 100644 --- a/modules/net-lb-app-ext/backends.tf +++ b/modules/net-lb-app-ext/backends.tf @@ -17,8 +17,12 @@ # tfdoc:file:description Backend groups and backend buckets resources. resource "google_compute_backend_bucket" "default" { - for_each = var.backend_buckets_config - project = var.project_id + for_each = var.backend_buckets_config + project = ( + each.value.project_id == null + ? var.project_id + : each.value.project_id + ) name = "${var.name}-${each.key}" bucket_name = each.value.bucket_name compression_mode = each.value.compression_mode diff --git a/modules/net-lb-app-ext/variables.tf b/modules/net-lb-app-ext/variables.tf index 7f0642d73..31ac6a1f8 100644 --- a/modules/net-lb-app-ext/variables.tf +++ b/modules/net-lb-app-ext/variables.tf @@ -23,6 +23,7 @@ variable "backend_buckets_config" { description = optional(string) edge_security_policy = optional(string) enable_cdn = optional(bool) + project_id = optional(string) cdn_policy = optional(object({ bypass_cache_on_request_headers = optional(list(string)) cache_mode = optional(string)