Skip to content

Commit

Permalink
Add fields pathTemplateMatch and pathTemplateRewrite to resource goog…
Browse files Browse the repository at this point in the history
…le_compute_region_url_map (#10157) (#17571)

[upstream:48d346d562b56f53668e2b34e1eab4a536ba097a]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Mar 13, 2024
1 parent da1142f commit 78dec39
Show file tree
Hide file tree
Showing 4 changed files with 311 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changelog/10157.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:enhancement
compute: added field `path_template_match` to resource `google_compute_region_url_map`
```
```release-note:enhancement
compute: added field `path_template_rewrite` to resource `google_compute_region_url_map`
```
64 changes: 64 additions & 0 deletions google/services/compute/resource_compute_region_url_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,19 @@ the provided metadata. Possible values: ["MATCH_ALL", "MATCH_ANY"]`,
},
},
},
"path_template_match": {
Type: schema.TypeString,
Optional: true,
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.`,
},
"prefix_match": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -1874,6 +1887,24 @@ header is replaced with contents of hostRewrite. The value must be between 1 and
portion of the request's path is replaced by pathPrefixRewrite. The value must
be between 1 and 1024 characters.`,
},
"path_template_rewrite": {
Type: schema.TypeString,
Optional: true,
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.`,
},
},
},
},
Expand Down Expand Up @@ -2857,6 +2888,7 @@ func flattenComputeRegionUrlMapPathMatcherRouteRulesMatchRules(v interface{}, d
"prefix_match": flattenComputeRegionUrlMapPathMatcherRouteRulesMatchRulesPrefixMatch(original["prefixMatch"], d, config),
"query_parameter_matches": flattenComputeRegionUrlMapPathMatcherRouteRulesMatchRulesQueryParameterMatches(original["queryParameterMatches"], d, config),
"regex_match": flattenComputeRegionUrlMapPathMatcherRouteRulesMatchRulesRegexMatch(original["regexMatch"], d, config),
"path_template_match": flattenComputeRegionUrlMapPathMatcherRouteRulesMatchRulesPathTemplateMatch(original["pathTemplateMatch"], d, config),
})
}
return transformed
Expand Down Expand Up @@ -3066,6 +3098,10 @@ func flattenComputeRegionUrlMapPathMatcherRouteRulesMatchRulesRegexMatch(v inter
return v
}

func flattenComputeRegionUrlMapPathMatcherRouteRulesMatchRulesPathTemplateMatch(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenComputeRegionUrlMapPathMatcherRouteRulesRouteAction(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -3412,6 +3448,8 @@ func flattenComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewrite(v inte
flattenComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewriteHostRewrite(original["hostRewrite"], d, config)
transformed["path_prefix_rewrite"] =
flattenComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewritePathPrefixRewrite(original["pathPrefixRewrite"], d, config)
transformed["path_template_rewrite"] =
flattenComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewritePathTemplateRewrite(original["pathTemplateRewrite"], d, config)
return []interface{}{transformed}
}
func flattenComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewriteHostRewrite(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
Expand All @@ -3422,6 +3460,10 @@ func flattenComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewritePathPre
return v
}

func flattenComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewritePathTemplateRewrite(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenComputeRegionUrlMapPathMatcherRouteRulesRouteActionWeightedBackendServices(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -5224,6 +5266,13 @@ func expandComputeRegionUrlMapPathMatcherRouteRulesMatchRules(v interface{}, d t
transformed["regexMatch"] = transformedRegexMatch
}

transformedPathTemplateMatch, err := expandComputeRegionUrlMapPathMatcherRouteRulesMatchRulesPathTemplateMatch(original["path_template_match"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPathTemplateMatch); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["pathTemplateMatch"] = transformedPathTemplateMatch
}

req = append(req, transformed)
}
return req, nil
Expand Down Expand Up @@ -5507,6 +5556,10 @@ func expandComputeRegionUrlMapPathMatcherRouteRulesMatchRulesRegexMatch(v interf
return v, nil
}

func expandComputeRegionUrlMapPathMatcherRouteRulesMatchRulesPathTemplateMatch(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandComputeRegionUrlMapPathMatcherRouteRulesRouteAction(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down Expand Up @@ -5951,6 +6004,13 @@ func expandComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewrite(v inter
transformed["pathPrefixRewrite"] = transformedPathPrefixRewrite
}

transformedPathTemplateRewrite, err := expandComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewritePathTemplateRewrite(original["path_template_rewrite"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPathTemplateRewrite); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["pathTemplateRewrite"] = transformedPathTemplateRewrite
}

return transformed, nil
}

Expand All @@ -5962,6 +6022,10 @@ func expandComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewritePathPref
return v, nil
}

func expandComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewritePathTemplateRewrite(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandComputeRegionUrlMapPathMatcherRouteRulesRouteActionWeightedBackendServices(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
req := make([]interface{}, 0, len(l))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,124 @@ resource "google_compute_region_health_check" "default" {
`, context)
}

func TestAccComputeRegionUrlMap_regionUrlMapPathTemplateMatchExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeRegionUrlMapDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeRegionUrlMap_regionUrlMapPathTemplateMatchExample(context),
},
{
ResourceName: "google_compute_region_url_map.urlmap",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"default_service", "region"},
},
},
})
}

func testAccComputeRegionUrlMap_regionUrlMapPathTemplateMatchExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_region_url_map" "urlmap" {
region = "us-central1"
name = "urlmap%{random_suffix}"
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 = "tf-test-home-service%{random_suffix}"
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 = "tf-test-cart-service%{random_suffix}"
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 = "tf-test-user-service%{random_suffix}"
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 = "tf-test-health-check%{random_suffix}"
check_interval_sec = 1
timeout_sec = 1
http_health_check {
port = 80
request_path = "/"
}
}
`, context)
}

func testAccCheckComputeRegionUrlMapDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down

0 comments on commit 78dec39

Please sign in to comment.