Skip to content

Commit

Permalink
Merge pull request hashicorp#145 from rileykarson/144-health-checks-c…
Browse files Browse the repository at this point in the history
…ount

Restrict the number of health_checks in Backend Service resources to exactly 1.
  • Loading branch information
stack72 authored Jun 21, 2017
2 parents 0421d67 + d11cb52 commit c91b31b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
4 changes: 3 additions & 1 deletion google/resource_compute_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ func resourceComputeBackendService() *schema.Resource {
"health_checks": &schema.Schema{
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Required: true,
Set: schema.HashString,
Required: true,
MinItems: 1,
MaxItems: 1,
},

"backend": &schema.Schema{
Expand Down
38 changes: 38 additions & 0 deletions google/resource_compute_backend_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,27 @@ func TestAccComputeBackendService_withConnectionDrainingAndUpdate(t *testing.T)
}
}

func TestAccComputeBackendService_withHttpsHealthCheck(t *testing.T) {
serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
var svc compute.BackendService

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeBackendServiceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeBackendService_withHttpsHealthCheck(serviceName, checkName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeBackendServiceExists(
"google_compute_backend_service.foobar", &svc),
),
},
},
})
}

func testAccCheckComputeBackendServiceDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)

Expand Down Expand Up @@ -416,3 +437,20 @@ resource "google_compute_http_health_check" "zero" {
}
`, serviceName, drainingTimeout, checkName)
}

func testAccComputeBackendService_withHttpsHealthCheck(serviceName, checkName string) string {
return fmt.Sprintf(`
resource "google_compute_backend_service" "foobar" {
name = "%s"
health_checks = ["${google_compute_https_health_check.zero.self_link}"]
protocol = "HTTPS"
}
resource "google_compute_https_health_check" "zero" {
name = "%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
`, serviceName, checkName)
}
4 changes: 3 additions & 1 deletion google/resource_compute_region_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ func resourceComputeRegionBackendService() *schema.Resource {
"health_checks": &schema.Schema{
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Required: true,
Set: schema.HashString,
Required: true,
MinItems: 1,
MaxItems: 1,
},

"backend": &schema.Schema{
Expand Down
5 changes: 3 additions & 2 deletions website/docs/r/compute_backend_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ The following arguments are supported:

* `name` - (Required) The name of the backend service.

* `health_checks` - (Required) Specifies a list of HTTP health check objects
for checking the health of the backend service.
* `health_checks` - (Required) Specifies a list of HTTP/HTTPS health checks
for checking the health of the backend service. Currently at most one health
check can be specified, and a health check is required.

- - -

Expand Down
5 changes: 3 additions & 2 deletions website/docs/r/compute_region_backend_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ The following arguments are supported:

* `name` - (Required) The name of the backend service.

* `health_checks` - (Required) Specifies a list of health check objects
for checking the health of the backend service.
* `health_checks` - (Required) Specifies a list of health checks
for checking the health of the backend service. Currently at most
one health check can be specified, and a health check is required.

- - -

Expand Down

0 comments on commit c91b31b

Please sign in to comment.