Make path_rule Optional in google_url_map's path_matcher block. (#118)

* Made path_rule optional for path_matcher in google_compute_url_map.

* Updated google_compute_url_map docs.

* Updated test configuration formatting.
This commit is contained in:
Riley Karson 2017-06-19 10:48:22 -07:00 committed by GitHub
parent 19feb0a350
commit aa48489a05
3 changed files with 210 additions and 150 deletions

View File

@ -90,7 +90,7 @@ func resourceComputeUrlMap() *schema.Resource {
"path_rule": &schema.Schema{
Type: schema.TypeList,
Required: true,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"paths": &schema.Schema{

View File

@ -82,6 +82,33 @@ func TestAccComputeUrlMap_advanced(t *testing.T) {
})
}
func TestAccComputeUrlMap_noPathRulesWithUpdate(t *testing.T) {
bsName := fmt.Sprintf("urlmap-test-%s", acctest.RandString(10))
hcName := fmt.Sprintf("urlmap-test-%s", acctest.RandString(10))
umName := fmt.Sprintf("urlmap-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeUrlMapDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeUrlMap_noPathRules(bsName, hcName, umName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeUrlMapExists(
"google_compute_url_map.foobar"),
),
},
resource.TestStep{
Config: testAccComputeUrlMap_basic1(bsName, hcName, umName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeUrlMapExists(
"google_compute_url_map.foobar"),
),
},
},
})
}
func testAccCheckComputeUrlMapDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
@ -129,38 +156,39 @@ func testAccCheckComputeUrlMapExists(n string) resource.TestCheckFunc {
func testAccComputeUrlMap_basic1(bsName, hcName, umName string) string {
return fmt.Sprintf(`
resource "google_compute_backend_service" "foobar" {
name = "urlmap-test-%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
name = "urlmap-test-%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
}
resource "google_compute_http_health_check" "zero" {
name = "urlmap-test-%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
name = "urlmap-test-%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_compute_url_map" "foobar" {
name = "urlmap-test-%s"
name = "urlmap-test-%s"
default_service = "${google_compute_backend_service.foobar.self_link}"
host_rule {
hosts = ["mysite.com", "myothersite.com"]
path_matcher = "boop"
}
host_rule {
hosts = ["mysite.com", "myothersite.com"]
path_matcher = "boop"
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "boop"
path_rule {
paths = ["/*"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "boop"
path_rule {
paths = ["/*"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
test {
host = "mysite.com"
path = "/*"
host = "mysite.com"
path = "/*"
service = "${google_compute_backend_service.foobar.self_link}"
}
}
@ -170,38 +198,39 @@ resource "google_compute_url_map" "foobar" {
func testAccComputeUrlMap_basic2(bsName, hcName, umName string) string {
return fmt.Sprintf(`
resource "google_compute_backend_service" "foobar" {
name = "urlmap-test-%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
name = "urlmap-test-%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
}
resource "google_compute_http_health_check" "zero" {
name = "urlmap-test-%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
name = "urlmap-test-%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_compute_url_map" "foobar" {
name = "urlmap-test-%s"
name = "urlmap-test-%s"
default_service = "${google_compute_backend_service.foobar.self_link}"
host_rule {
hosts = ["mysite.com", "myothersite.com"]
path_matcher = "blip"
}
host_rule {
hosts = ["mysite.com", "myothersite.com"]
path_matcher = "blip"
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "blip"
path_rule {
paths = ["/*", "/home"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "blip"
path_rule {
paths = ["/*", "/home"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
test {
host = "mysite.com"
path = "/test"
host = "mysite.com"
path = "/test"
service = "${google_compute_backend_service.foobar.self_link}"
}
}
@ -210,113 +239,155 @@ resource "google_compute_url_map" "foobar" {
var testAccComputeUrlMap_advanced1 = fmt.Sprintf(`
resource "google_compute_backend_service" "foobar" {
name = "urlmap-test-%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
name = "urlmap-test-%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
}
resource "google_compute_http_health_check" "zero" {
name = "urlmap-test-%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
name = "urlmap-test-%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_compute_url_map" "foobar" {
name = "urlmap-test-%s"
name = "urlmap-test-%s"
default_service = "${google_compute_backend_service.foobar.self_link}"
host_rule {
hosts = ["mysite.com", "myothersite.com"]
path_matcher = "blop"
}
host_rule {
hosts = ["mysite.com", "myothersite.com"]
path_matcher = "blop"
}
host_rule {
hosts = ["myfavoritesite.com"]
path_matcher = "blip"
}
host_rule {
hosts = ["myfavoritesite.com"]
path_matcher = "blip"
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "blop"
path_rule {
paths = ["/*", "/home"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "blop"
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "blip"
path_rule {
paths = ["/*", "/home"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
path_rule {
paths = ["/*", "/home"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "blip"
path_rule {
paths = ["/*", "/home"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
}
`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
var testAccComputeUrlMap_advanced2 = fmt.Sprintf(`
resource "google_compute_backend_service" "foobar" {
name = "urlmap-test-%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
name = "urlmap-test-%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
}
resource "google_compute_http_health_check" "zero" {
name = "urlmap-test-%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
name = "urlmap-test-%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_compute_url_map" "foobar" {
name = "urlmap-test-%s"
name = "urlmap-test-%s"
default_service = "${google_compute_backend_service.foobar.self_link}"
host_rule {
hosts = ["mysite.com", "myothersite.com"]
path_matcher = "blep"
}
host_rule {
hosts = ["mysite.com", "myothersite.com"]
path_matcher = "blep"
}
host_rule {
hosts = ["myfavoritesite.com"]
path_matcher = "blip"
}
host_rule {
hosts = ["myfavoritesite.com"]
path_matcher = "blip"
}
host_rule {
hosts = ["myleastfavoritesite.com"]
path_matcher = "blub"
}
host_rule {
hosts = ["myleastfavoritesite.com"]
path_matcher = "blub"
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "blep"
path_rule {
paths = ["/home"]
service = "${google_compute_backend_service.foobar.self_link}"
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "blep"
path_rule {
paths = ["/login"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
path_rule {
paths = ["/home"]
service = "${google_compute_backend_service.foobar.self_link}"
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "blub"
path_rule {
paths = ["/*", "/blub"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
path_rule {
paths = ["/login"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "blip"
path_rule {
paths = ["/*", "/home"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "blub"
path_rule {
paths = ["/*", "/blub"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "blip"
path_rule {
paths = ["/*", "/home"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
}
`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
func testAccComputeUrlMap_noPathRules(bsName, hcName, umName string) string {
return fmt.Sprintf(`
resource "google_compute_backend_service" "foobar" {
name = "urlmap-test-%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
}
resource "google_compute_http_health_check" "zero" {
name = "urlmap-test-%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_compute_url_map" "foobar" {
name = "urlmap-test-%s"
default_service = "${google_compute_backend_service.foobar.self_link}"
host_rule {
hosts = ["mysite.com", "myothersite.com"]
path_matcher = "boop"
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "boop"
}
test {
host = "mysite.com"
path = "/*"
service = "${google_compute_backend_service.foobar.self_link}"
}
}
`, bsName, hcName, umName)
}

View File

@ -96,10 +96,7 @@ resource "google_storage_bucket" "static" {
The following arguments are supported:
* `default_service` - (Required) The URL of the backend service or backend bucket to use when none
of the given rules match. See the documentation for formatting the service/bucket
URL
[here](https://cloud.google.com/compute/docs/reference/latest/urlMaps#defaultService)
* `default_service` - (Required) The backend service or backend bucket to use when none of the given rules match.
* `name` - (Required) A unique name for the resource, required by GCE.
Changing this forces a new resource to be created.
@ -108,50 +105,42 @@ The following arguments are supported:
* `description` - (Optional) A brief description of this resource.
* `host_rule` - (Optional) A list of host rules. See below for configuration
options.
* `host_rule` - (Optional) A list of host rules. Multiple blocks of this type are permitted. Structure is documented below.
* `path_matcher` - (Optional) A list of paths to match. See below for
configuration options.
* `path_matcher` - (Optional) A list of paths to match. Structure is documented below.
* `project` - (Optional) The project in which the resource belongs. If it
is not provided, the provider project is used.
* `test` - (Optional) The test to perform. See below for configuration options.
* `test` - (Optional) The test to perform. Multiple blocks of this type are permitted. Structure is documented below.
The `host_rule` block supports: (This block can be defined multiple times).
The `host_rule` block supports:
* `hosts` (Required) - A list of hosts to match against. See the documentation
for formatting each host
[here](https://cloud.google.com/compute/docs/reference/latest/urlMaps#hostRules.hosts)
* `hosts` (Required) - The list of [host patterns](https://cloud.google.com/compute/docs/reference/latest/urlMaps#hostRules.hosts)
to match.
* `description` - (Optional) An optional description of the host rule.
* `path_matcher` - (Required) The name of the `path_matcher` (defined below)
to apply this host rule to.
* `path_matcher` - (Required) The name of the `path_matcher` to apply this host rule to.
The `path_matcher` block supports: (This block can be defined multiple times)
The `path_matcher` block supports:
* `default_service` - (Required) The URL for the backend service or backend bucket to use if none
of the given paths match. See the documentation for formatting the service/bucket
URL [here](https://cloud.google.com/compute/docs/reference/latest/urlMaps#pathMatcher.defaultService)
* `name` - (Required) The name of the `path_matcher` resource.
* `name` - (Required) The name of the `path_matcher` resource. Used by the
`host_rule` block above.
* `default_service` - (Required) The backend service or backend bucket to use if none of the given paths match.
* `description` - (Optional) An optional description of the host rule.
The `path_matcher.path_rule` sub-block supports: (This block can be defined
multiple times)
* `path_rule` - (Optional) A list of path rules. Multiple blocks of this type are permitted. Structure is documented below.
* `paths` - (Required) The list of paths to match against. See the
documentation for formatting these [here](https://cloud.google.com/compute/docs/reference/latest/urlMaps#pathMatchers.pathRules.paths)
The `path_rule` block supports:
* `service` - (Required) The URL for the backend service or backend bucket to use if any
of the given paths match. See the documentation for formatting the service/bucket
URL [here](https://cloud.google.com/compute/docs/reference/latest/urlMaps#pathMatcher.defaultService)
* `paths` - (Required) The list of [paths](https://cloud.google.com/compute/docs/reference/latest/urlMaps#pathMatchers.pathRules.paths)
to match against.
The optional `test` block supports: (This block can be defined multiple times)
* `service` - (Required) The backend service or backend bucket to use if any of the given paths match.
The `test` block supports:
* `service` - (Required) The backend service or backend bucket that should be matched by this test.