Skip to content

Commit

Permalink
Fix path_matcher in region url maps (#4298) (#2810)
Browse files Browse the repository at this point in the history
* Fix path_matcher in region url maps

The default_service in path_matcher is actually not required as it should be default_service or default_url_redirect.

Further info in https://cloud.google.com/compute/docs/reference/rest/v1/regionUrlMaps
> pathMatchers[].defaultService
>> Only one of defaultService, defaultUrlRedirect or defaultRouteAction.weightedBackendService must be set.

* Add testcase

* Update function name

Co-authored-by: Gilles Margerie <[email protected]>
Signed-off-by: Modular Magician <[email protected]>

Co-authored-by: Gilles Margerie <[email protected]>
  • Loading branch information
modular-magician and Gilles Margerie authored Dec 22, 2020
1 parent a4751c0 commit 3ad4530
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/4298.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
google_compute_region_url_map: removed requirement for default_service, as it should be a choice of default_service or default_url_redirect
```
12 changes: 6 additions & 6 deletions google-beta/resource_compute_region_url_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,20 @@ you create the resource.`,
Description: `The list of named PathMatchers to use against the URL.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: `The name to which this PathMatcher is referred by the HostRule.`,
},
"default_service": {
Type: schema.TypeString,
Required: true,
Optional: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
Description: `A reference to a RegionBackendService resource. This will be used if
none of the pathRules defined by this PathMatcher is matched by
the URL's path portion.`,
ExactlyOneOf: []string{},
},
"name": {
Type: schema.TypeString,
Required: true,
Description: `The name to which this PathMatcher is referred by the HostRule.`,
},
"default_url_redirect": {
Type: schema.TypeList,
Optional: true,
Expand Down
46 changes: 46 additions & 0 deletions google-beta/resource_compute_region_url_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,28 @@ func TestAccComputeRegionUrlMap_defaultUrlRedirect(t *testing.T) {
})
}

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

randomSuffix := randString(t, 10)

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeUrlMapDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeRegionUrlMap_defaultUrlRedirectWithinPathMatcherConfig(randomSuffix),
},
{
ResourceName: "google_compute_region_url_map.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccComputeRegionUrlMap_basic1(randomSuffix string) string {
return fmt.Sprintf(`
resource "google_compute_region_backend_service" "foobar" {
Expand Down Expand Up @@ -853,3 +875,27 @@ resource "google_compute_region_url_map" "foobar" {
}
`, randomSuffix)
}

func testAccComputeRegionUrlMap_defaultUrlRedirectWithinPathMatcherConfig(randomSuffix string) string {
return fmt.Sprintf(`
resource "google_compute_region_url_map" "foobar" {
name = "urlmap-test-%s"
default_url_redirect {
https_redirect = true
strip_query = false
}
host_rule {
hosts = ["mysite.com"]
path_matcher = "allpaths"
}
path_matcher {
name = "allpaths"
default_url_redirect {
https_redirect = true
strip_query = false
}
}
}
`, randomSuffix)
}
2 changes: 1 addition & 1 deletion website/docs/r/compute_region_url_map.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ The `host_rule` block supports:
The `path_matcher` block supports:

* `default_service` -
(Required)
(Optional)
A reference to a RegionBackendService resource. This will be used if
none of the pathRules defined by this PathMatcher is matched by
the URL's path portion.
Expand Down

0 comments on commit 3ad4530

Please sign in to comment.