Skip to content

Commit e922394

Browse files
Add fields pathTemplateMatch and pathTemplateRewrite to resource google_compute_region_url_map (#10157)
[upstream:48d346d562b56f53668e2b34e1eab4a536ba097a] Signed-off-by: Modular Magician <[email protected]>
1 parent 39d359d commit e922394

File tree

4 files changed

+311
-0
lines changed

4 files changed

+311
-0
lines changed

.changelog/10157.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:enhancement
2+
compute: added field `path_template_match` to resource `google_compute_region_url_map`
3+
```
4+
```release-note:enhancement
5+
compute: added field `path_template_rewrite` to resource `google_compute_region_url_map`
6+
```

google-beta/services/compute/resource_compute_region_url_map.go

+64
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,19 @@ the provided metadata. Possible values: ["MATCH_ALL", "MATCH_ANY"]`,
15141514
},
15151515
},
15161516
},
1517+
"path_template_match": {
1518+
Type: schema.TypeString,
1519+
Optional: true,
1520+
Description: `For satisfying the matchRule condition, the path of the request
1521+
must match the wildcard pattern specified in pathTemplateMatch
1522+
after removing any query parameters and anchor that may be part
1523+
of the original URL.
1524+
1525+
pathTemplateMatch must be between 1 and 255 characters
1526+
(inclusive). The pattern specified by pathTemplateMatch may
1527+
have at most 5 wildcard operators and at most 5 variable
1528+
captures in total.`,
1529+
},
15171530
"prefix_match": {
15181531
Type: schema.TypeString,
15191532
Optional: true,
@@ -1874,6 +1887,24 @@ header is replaced with contents of hostRewrite. The value must be between 1 and
18741887
portion of the request's path is replaced by pathPrefixRewrite. The value must
18751888
be between 1 and 1024 characters.`,
18761889
},
1890+
"path_template_rewrite": {
1891+
Type: schema.TypeString,
1892+
Optional: true,
1893+
Description: `Prior to forwarding the request to the selected origin, if the
1894+
request matched a pathTemplateMatch, the matching portion of the
1895+
request's path is replaced re-written using the pattern specified
1896+
by pathTemplateRewrite.
1897+
1898+
pathTemplateRewrite must be between 1 and 255 characters
1899+
(inclusive), must start with a '/', and must only use variables
1900+
captured by the route's pathTemplate matchers.
1901+
1902+
pathTemplateRewrite may only be used when all of a route's
1903+
MatchRules specify pathTemplate.
1904+
1905+
Only one of pathPrefixRewrite and pathTemplateRewrite may be
1906+
specified.`,
1907+
},
18771908
},
18781909
},
18791910
},
@@ -2857,6 +2888,7 @@ func flattenComputeRegionUrlMapPathMatcherRouteRulesMatchRules(v interface{}, d
28572888
"prefix_match": flattenComputeRegionUrlMapPathMatcherRouteRulesMatchRulesPrefixMatch(original["prefixMatch"], d, config),
28582889
"query_parameter_matches": flattenComputeRegionUrlMapPathMatcherRouteRulesMatchRulesQueryParameterMatches(original["queryParameterMatches"], d, config),
28592890
"regex_match": flattenComputeRegionUrlMapPathMatcherRouteRulesMatchRulesRegexMatch(original["regexMatch"], d, config),
2891+
"path_template_match": flattenComputeRegionUrlMapPathMatcherRouteRulesMatchRulesPathTemplateMatch(original["pathTemplateMatch"], d, config),
28602892
})
28612893
}
28622894
return transformed
@@ -3066,6 +3098,10 @@ func flattenComputeRegionUrlMapPathMatcherRouteRulesMatchRulesRegexMatch(v inter
30663098
return v
30673099
}
30683100

3101+
func flattenComputeRegionUrlMapPathMatcherRouteRulesMatchRulesPathTemplateMatch(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
3102+
return v
3103+
}
3104+
30693105
func flattenComputeRegionUrlMapPathMatcherRouteRulesRouteAction(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
30703106
if v == nil {
30713107
return nil
@@ -3412,6 +3448,8 @@ func flattenComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewrite(v inte
34123448
flattenComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewriteHostRewrite(original["hostRewrite"], d, config)
34133449
transformed["path_prefix_rewrite"] =
34143450
flattenComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewritePathPrefixRewrite(original["pathPrefixRewrite"], d, config)
3451+
transformed["path_template_rewrite"] =
3452+
flattenComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewritePathTemplateRewrite(original["pathTemplateRewrite"], d, config)
34153453
return []interface{}{transformed}
34163454
}
34173455
func flattenComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewriteHostRewrite(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
@@ -3422,6 +3460,10 @@ func flattenComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewritePathPre
34223460
return v
34233461
}
34243462

3463+
func flattenComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewritePathTemplateRewrite(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
3464+
return v
3465+
}
3466+
34253467
func flattenComputeRegionUrlMapPathMatcherRouteRulesRouteActionWeightedBackendServices(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
34263468
if v == nil {
34273469
return v
@@ -5224,6 +5266,13 @@ func expandComputeRegionUrlMapPathMatcherRouteRulesMatchRules(v interface{}, d t
52245266
transformed["regexMatch"] = transformedRegexMatch
52255267
}
52265268

5269+
transformedPathTemplateMatch, err := expandComputeRegionUrlMapPathMatcherRouteRulesMatchRulesPathTemplateMatch(original["path_template_match"], d, config)
5270+
if err != nil {
5271+
return nil, err
5272+
} else if val := reflect.ValueOf(transformedPathTemplateMatch); val.IsValid() && !tpgresource.IsEmptyValue(val) {
5273+
transformed["pathTemplateMatch"] = transformedPathTemplateMatch
5274+
}
5275+
52275276
req = append(req, transformed)
52285277
}
52295278
return req, nil
@@ -5507,6 +5556,10 @@ func expandComputeRegionUrlMapPathMatcherRouteRulesMatchRulesRegexMatch(v interf
55075556
return v, nil
55085557
}
55095558

5559+
func expandComputeRegionUrlMapPathMatcherRouteRulesMatchRulesPathTemplateMatch(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
5560+
return v, nil
5561+
}
5562+
55105563
func expandComputeRegionUrlMapPathMatcherRouteRulesRouteAction(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
55115564
l := v.([]interface{})
55125565
if len(l) == 0 || l[0] == nil {
@@ -5951,6 +6004,13 @@ func expandComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewrite(v inter
59516004
transformed["pathPrefixRewrite"] = transformedPathPrefixRewrite
59526005
}
59536006

6007+
transformedPathTemplateRewrite, err := expandComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewritePathTemplateRewrite(original["path_template_rewrite"], d, config)
6008+
if err != nil {
6009+
return nil, err
6010+
} else if val := reflect.ValueOf(transformedPathTemplateRewrite); val.IsValid() && !tpgresource.IsEmptyValue(val) {
6011+
transformed["pathTemplateRewrite"] = transformedPathTemplateRewrite
6012+
}
6013+
59546014
return transformed, nil
59556015
}
59566016

@@ -5962,6 +6022,10 @@ func expandComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewritePathPref
59626022
return v, nil
59636023
}
59646024

6025+
func expandComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewritePathTemplateRewrite(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
6026+
return v, nil
6027+
}
6028+
59656029
func expandComputeRegionUrlMapPathMatcherRouteRulesRouteActionWeightedBackendServices(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
59666030
l := v.([]interface{})
59676031
req := make([]interface{}, 0, len(l))

google-beta/services/compute/resource_compute_region_url_map_generated_test.go

+118
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,124 @@ resource "google_compute_region_health_check" "default" {
756756
`, context)
757757
}
758758

759+
func TestAccComputeRegionUrlMap_regionUrlMapPathTemplateMatchExample(t *testing.T) {
760+
t.Parallel()
761+
762+
context := map[string]interface{}{
763+
"random_suffix": acctest.RandString(t, 10),
764+
}
765+
766+
acctest.VcrTest(t, resource.TestCase{
767+
PreCheck: func() { acctest.AccTestPreCheck(t) },
768+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
769+
CheckDestroy: testAccCheckComputeRegionUrlMapDestroyProducer(t),
770+
Steps: []resource.TestStep{
771+
{
772+
Config: testAccComputeRegionUrlMap_regionUrlMapPathTemplateMatchExample(context),
773+
},
774+
{
775+
ResourceName: "google_compute_region_url_map.urlmap",
776+
ImportState: true,
777+
ImportStateVerify: true,
778+
ImportStateVerifyIgnore: []string{"default_service", "region"},
779+
},
780+
},
781+
})
782+
}
783+
784+
func testAccComputeRegionUrlMap_regionUrlMapPathTemplateMatchExample(context map[string]interface{}) string {
785+
return acctest.Nprintf(`
786+
resource "google_compute_region_url_map" "urlmap" {
787+
region = "us-central1"
788+
789+
name = "urlmap%{random_suffix}"
790+
description = "a description"
791+
792+
default_service = google_compute_region_backend_service.home-backend.id
793+
794+
host_rule {
795+
hosts = ["mysite.com"]
796+
path_matcher = "mysite"
797+
}
798+
799+
path_matcher {
800+
name = "mysite"
801+
default_service = google_compute_region_backend_service.home-backend.id
802+
803+
route_rules {
804+
match_rules {
805+
path_template_match = "/xyzwebservices/v2/xyz/users/{username=*}/carts/{cartid=**}"
806+
}
807+
service = google_compute_region_backend_service.cart-backend.id
808+
priority = 1
809+
route_action {
810+
url_rewrite {
811+
path_template_rewrite = "/{username}-{cartid}/"
812+
}
813+
}
814+
}
815+
816+
route_rules {
817+
match_rules {
818+
path_template_match = "/xyzwebservices/v2/xyz/users/*/accountinfo/*"
819+
}
820+
service = google_compute_region_backend_service.user-backend.id
821+
priority = 2
822+
}
823+
}
824+
}
825+
826+
resource "google_compute_region_backend_service" "home-backend" {
827+
region = "us-central1"
828+
829+
name = "tf-test-home-service%{random_suffix}"
830+
port_name = "http"
831+
protocol = "HTTP"
832+
timeout_sec = 10
833+
load_balancing_scheme = "EXTERNAL_MANAGED"
834+
835+
health_checks = [google_compute_region_health_check.default.id]
836+
}
837+
838+
resource "google_compute_region_backend_service" "cart-backend" {
839+
region = "us-central1"
840+
841+
name = "tf-test-cart-service%{random_suffix}"
842+
port_name = "http"
843+
protocol = "HTTP"
844+
timeout_sec = 10
845+
load_balancing_scheme = "EXTERNAL_MANAGED"
846+
847+
health_checks = [google_compute_region_health_check.default.id]
848+
}
849+
850+
resource "google_compute_region_backend_service" "user-backend" {
851+
region = "us-central1"
852+
853+
name = "tf-test-user-service%{random_suffix}"
854+
port_name = "http"
855+
protocol = "HTTP"
856+
timeout_sec = 10
857+
load_balancing_scheme = "EXTERNAL_MANAGED"
858+
859+
health_checks = [google_compute_region_health_check.default.id]
860+
}
861+
862+
resource "google_compute_region_health_check" "default" {
863+
region = "us-central1"
864+
865+
name = "tf-test-health-check%{random_suffix}"
866+
check_interval_sec = 1
867+
timeout_sec = 1
868+
http_health_check {
869+
port = 80
870+
request_path = "/"
871+
}
872+
}
873+
874+
`, context)
875+
}
876+
759877
func testAccCheckComputeRegionUrlMapDestroyProducer(t *testing.T) func(s *terraform.State) error {
760878
return func(s *terraform.State) error {
761879
for name, rs := range s.RootModule().Resources {

0 commit comments

Comments
 (0)