Skip to content

Commit c91b31b

Browse files
authored
Merge pull request hashicorp#145 from rileykarson/144-health-checks-count
Restrict the number of health_checks in Backend Service resources to exactly 1.
2 parents 0421d67 + d11cb52 commit c91b31b

5 files changed

+50
-6
lines changed

google/resource_compute_backend_service.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ func resourceComputeBackendService() *schema.Resource {
4040
"health_checks": &schema.Schema{
4141
Type: schema.TypeSet,
4242
Elem: &schema.Schema{Type: schema.TypeString},
43-
Required: true,
4443
Set: schema.HashString,
44+
Required: true,
45+
MinItems: 1,
46+
MaxItems: 1,
4547
},
4648

4749
"backend": &schema.Schema{

google/resource_compute_backend_service_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,27 @@ func TestAccComputeBackendService_withConnectionDrainingAndUpdate(t *testing.T)
171171
}
172172
}
173173

174+
func TestAccComputeBackendService_withHttpsHealthCheck(t *testing.T) {
175+
serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
176+
checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
177+
var svc compute.BackendService
178+
179+
resource.Test(t, resource.TestCase{
180+
PreCheck: func() { testAccPreCheck(t) },
181+
Providers: testAccProviders,
182+
CheckDestroy: testAccCheckComputeBackendServiceDestroy,
183+
Steps: []resource.TestStep{
184+
resource.TestStep{
185+
Config: testAccComputeBackendService_withHttpsHealthCheck(serviceName, checkName),
186+
Check: resource.ComposeTestCheckFunc(
187+
testAccCheckComputeBackendServiceExists(
188+
"google_compute_backend_service.foobar", &svc),
189+
),
190+
},
191+
},
192+
})
193+
}
194+
174195
func testAccCheckComputeBackendServiceDestroy(s *terraform.State) error {
175196
config := testAccProvider.Meta().(*Config)
176197

@@ -416,3 +437,20 @@ resource "google_compute_http_health_check" "zero" {
416437
}
417438
`, serviceName, drainingTimeout, checkName)
418439
}
440+
441+
func testAccComputeBackendService_withHttpsHealthCheck(serviceName, checkName string) string {
442+
return fmt.Sprintf(`
443+
resource "google_compute_backend_service" "foobar" {
444+
name = "%s"
445+
health_checks = ["${google_compute_https_health_check.zero.self_link}"]
446+
protocol = "HTTPS"
447+
}
448+
449+
resource "google_compute_https_health_check" "zero" {
450+
name = "%s"
451+
request_path = "/"
452+
check_interval_sec = 1
453+
timeout_sec = 1
454+
}
455+
`, serviceName, checkName)
456+
}

google/resource_compute_region_backend_service.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ func resourceComputeRegionBackendService() *schema.Resource {
3737
"health_checks": &schema.Schema{
3838
Type: schema.TypeSet,
3939
Elem: &schema.Schema{Type: schema.TypeString},
40-
Required: true,
4140
Set: schema.HashString,
41+
Required: true,
42+
MinItems: 1,
43+
MaxItems: 1,
4244
},
4345

4446
"backend": &schema.Schema{

website/docs/r/compute_backend_service.html.markdown

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ The following arguments are supported:
6969

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

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

7576
- - -
7677

website/docs/r/compute_region_backend_service.html.markdown

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ The following arguments are supported:
6969

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

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

7576
- - -
7677

0 commit comments

Comments
 (0)