From 5d05d13bc31472c5d777e656ba3677cae6def4f3 Mon Sep 17 00:00:00 2001 From: Rostislav Bobrovsky Date: Mon, 11 Mar 2024 16:31:48 +0000 Subject: [PATCH] Add fields pathTemplateMatch and pathTemplateRewrite to resource google_compute_region_url_map --- mmv1/products/compute/RegionUrlMap.yaml | 38 ++++++++ .../region_url_map_path_template_match.tf.erb | 90 +++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 mmv1/templates/terraform/examples/region_url_map_path_template_match.tf.erb diff --git a/mmv1/products/compute/RegionUrlMap.yaml b/mmv1/products/compute/RegionUrlMap.yaml index 69d8e8fcb7ae..2d2645f08398 100644 --- a/mmv1/products/compute/RegionUrlMap.yaml +++ b/mmv1/products/compute/RegionUrlMap.yaml @@ -130,6 +130,15 @@ examples: skip_docs: true skip_test: true # Similar to other samples min_version: beta + - !ruby/object:Provider::Terraform::Examples + name: "region_url_map_path_template_match" + primary_resource_id: "urlmap" + vars: + url_map_name: "urlmap" + home_backend_service_name: "home-service" + cart_backend_service_name: "cart-service" + user_backend_service_name: "user-service" + health_check_name: "health-check" parameters: - !ruby/object:Api::Type::ResourceRef name: 'region' @@ -558,6 +567,18 @@ properties: and anchor supplied with the original URL. For regular expression grammar please see en.cppreference.com/w/cpp/regex/ecmascript Only one of prefixMatch, fullPathMatch or regexMatch must be specified. + - !ruby/object:Api::Type::String + name: 'pathTemplateMatch' + description: | + For satisfying the matchRule condition, the path of the request + must match the wildcard pattern specified in pathTemplateMatch + after removing any query parameters and anchor that may be part + of the original URL. + + pathTemplateMatch must be between 1 and 255 characters + (inclusive). The pattern specified by pathTemplateMatch may + have at most 5 wildcard operators and at most 5 variable + captures in total. - !ruby/object:Api::Type::NestedObject name: 'routeAction' description: | @@ -784,6 +805,23 @@ properties: Prior to forwarding the request to the selected backend service, the matching portion of the request's path is replaced by pathPrefixRewrite. The value must be between 1 and 1024 characters. + - !ruby/object:Api::Type::String + name: 'pathTemplateRewrite' + description: | + Prior to forwarding the request to the selected origin, if the + request matched a pathTemplateMatch, the matching portion of the + request's path is replaced re-written using the pattern specified + by pathTemplateRewrite. + + pathTemplateRewrite must be between 1 and 255 characters + (inclusive), must start with a '/', and must only use variables + captured by the route's pathTemplate matchers. + + pathTemplateRewrite may only be used when all of a route's + MatchRules specify pathTemplate. + + Only one of pathPrefixRewrite and pathTemplateRewrite may be + specified. - !ruby/object:Api::Type::Array name: 'weightedBackendServices' description: | diff --git a/mmv1/templates/terraform/examples/region_url_map_path_template_match.tf.erb b/mmv1/templates/terraform/examples/region_url_map_path_template_match.tf.erb new file mode 100644 index 000000000000..5a7008e1b80b --- /dev/null +++ b/mmv1/templates/terraform/examples/region_url_map_path_template_match.tf.erb @@ -0,0 +1,90 @@ +# [START cloudloadbalancing_url_map_path_template_match] +resource "google_compute_region_url_map" "<%= ctx[:primary_resource_id] %>" { + region = "us-central1" + + name = "<%= ctx[:vars]['url_map_name'] %>" + description = "a description" + + default_service = google_compute_region_backend_service.home-backend.id + + host_rule { + hosts = ["mysite.com"] + path_matcher = "mysite" + } + + path_matcher { + name = "mysite" + default_service = google_compute_region_backend_service.home-backend.id + + route_rules { + match_rules { + path_template_match = "/xyzwebservices/v2/xyz/users/{username=*}/carts/{cartid=**}" + } + service = google_compute_region_backend_service.cart-backend.id + priority = 1 + route_action { + url_rewrite { + path_template_rewrite = "/{username}-{cartid}/" + } + } + } + + route_rules { + match_rules { + path_template_match = "/xyzwebservices/v2/xyz/users/*/accountinfo/*" + } + service = google_compute_region_backend_service.user-backend.id + priority = 2 + } + } +} + +resource "google_compute_region_backend_service" "home-backend" { + region = "us-central1" + + name = "<%= ctx[:vars]['home_backend_service_name'] %>" + port_name = "http" + protocol = "HTTP" + timeout_sec = 10 + load_balancing_scheme = "EXTERNAL_MANAGED" + + health_checks = [google_compute_region_health_check.default.id] +} + +resource "google_compute_region_backend_service" "cart-backend" { + region = "us-central1" + + name = "<%= ctx[:vars]['cart_backend_service_name'] %>" + port_name = "http" + protocol = "HTTP" + timeout_sec = 10 + load_balancing_scheme = "EXTERNAL_MANAGED" + + health_checks = [google_compute_region_health_check.default.id] +} + +resource "google_compute_region_backend_service" "user-backend" { + region = "us-central1" + + name = "<%= ctx[:vars]['user_backend_service_name'] %>" + port_name = "http" + protocol = "HTTP" + timeout_sec = 10 + load_balancing_scheme = "EXTERNAL_MANAGED" + + health_checks = [google_compute_region_health_check.default.id] +} + +resource "google_compute_region_health_check" "default" { + region = "us-central1" + + name = "<%= ctx[:vars]['health_check_name'] %>" + check_interval_sec = 1 + timeout_sec = 1 + http_health_check { + port = 80 + request_path = "/" + } +} + +# [END cloudloadbalancing_url_map_path_template_match]