From 73b608813262d984c048cdf0a95caa29d74cd8b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Taneli=20Lepp=C3=A4?= Date: Tue, 19 Nov 2024 09:03:11 +0100 Subject: [PATCH] Add path_template_match and path_template_rewrite support to net-lb-app-ext (required for React apps for example). --- modules/net-lb-app-ext/README.md | 2 +- modules/net-lb-app-ext/urlmap.tf | 10 ++++++++-- modules/net-lb-app-ext/variables-urlmap.tf | 15 +++++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/modules/net-lb-app-ext/README.md b/modules/net-lb-app-ext/README.md index 46afaec9b..8f51535f0 100644 --- a/modules/net-lb-app-ext/README.md +++ b/modules/net-lb-app-ext/README.md @@ -1060,7 +1060,7 @@ After provisioning this change, and verifying that the new certificate is provis | [ports](variables.tf#L189) | Optional ports for HTTP load balancer, valid ports are 80 and 8080. | list(string) | | null | | [protocol](variables.tf#L200) | Protocol supported by this load balancer. | string | | "HTTP" | | [ssl_certificates](variables.tf#L213) | 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({…}) | | {…} | +| [urlmap_config](variables-urlmap.tf#L19) | The URL map configuration. | object({…}) | | {…} | | [use_classic_version](variables.tf#L230) | Use classic Global Load Balancer. | bool | | true | ## Outputs diff --git a/modules/net-lb-app-ext/urlmap.tf b/modules/net-lb-app-ext/urlmap.tf index 51d5e9d1b..d215fdabc 100644 --- a/modules/net-lb-app-ext/urlmap.tf +++ b/modules/net-lb-app-ext/urlmap.tf @@ -703,6 +703,11 @@ resource "google_compute_url_map" "default" { ? match_rules.value.path.value : null ) + path_template_match = ( + try(match_rules.value.path.type, null) == "template" + ? match_rules.value.path.value + : null + ) dynamic "header_matches" { for_each = toset(coalesce(match_rules.value.headers, [])) iterator = h @@ -873,8 +878,9 @@ resource "google_compute_url_map" "default" { : [route_action.value.url_rewrite] ) content { - host_rewrite = url_rewrite.value.host - path_prefix_rewrite = url_rewrite.value.path_prefix + host_rewrite = url_rewrite.value.host + path_prefix_rewrite = url_rewrite.value.path_prefix + path_template_rewrite = url_rewrite.value.path_template } } dynamic "weighted_backend_services" { diff --git a/modules/net-lb-app-ext/variables-urlmap.tf b/modules/net-lb-app-ext/variables-urlmap.tf index 88aedc873..c7745e4a2 100644 --- a/modules/net-lb-app-ext/variables-urlmap.tf +++ b/modules/net-lb-app-ext/variables-urlmap.tf @@ -57,8 +57,9 @@ variable "urlmap_config" { nanos = optional(number) })) url_rewrite = optional(object({ - host = optional(string) - path_prefix = optional(string) + host = optional(string) + path_prefix = optional(string) + path_template = optional(string) })) weighted_backend_services = optional(map(object({ weight = number @@ -142,8 +143,9 @@ variable "urlmap_config" { nanos = optional(number) })) url_rewrite = optional(object({ - host = optional(string) - path_prefix = optional(string) + host = optional(string) + path_prefix = optional(string) + path_template = optional(string) })) weighted_backend_services = optional(map(object({ weight = number @@ -330,8 +332,9 @@ variable "urlmap_config" { nanos = optional(number) })) url_rewrite = optional(object({ - host = optional(string) - path_prefix = optional(string) + host = optional(string) + path_prefix = optional(string) + path_template = optional(string) })) weighted_backend_services = optional(map(object({ weight = number