From cbcdf9d9b7847ccaac021b23588b633a9e59c55b Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Tue, 18 Aug 2020 10:24:05 -0700 Subject: [PATCH] Fix grpc healthcheck behaviour. --- .../terraform/encoders/health_check_type.erb | 15 +++++++++++++++ .../tests/resource_compute_health_check_test.go | 2 +- ...source_compute_region_health_check_test.go.erb | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/templates/terraform/encoders/health_check_type.erb b/templates/terraform/encoders/health_check_type.erb index 55a1ec13d362..efedcc412be0 100644 --- a/templates/terraform/encoders/health_check_type.erb +++ b/templates/terraform/encoders/health_check_type.erb @@ -84,4 +84,19 @@ if _, ok := d.GetOk("ssl_health_check"); ok { return obj, nil } +if _, ok := d.GetOk("grpc_health_check"); ok { + hc := d.Get("grpc_health_check").([]interface{})[0] + ps := hc.(map[string]interface{})["port_specification"] + pn := hc.(map[string]interface{})["port_name"] + + if ps == "USE_FIXED_PORT" || (ps == "" && pn == "") { + m := obj["grpcHealthCheck"].(map[string]interface{}) + if m["port"] == nil { + return nil, fmt.Errorf("error in HealthCheck %s: `port` must be set for GRPC health checks`.", d.Get("name").(string)) + } + } + obj["type"] = "GRPC" + return obj, nil +} + return nil, fmt.Errorf("error in HealthCheck %s: No health check block specified.", d.Get("name").(string)) diff --git a/third_party/terraform/tests/resource_compute_health_check_test.go b/third_party/terraform/tests/resource_compute_health_check_test.go index 383b86e783fc..84694f93eba5 100644 --- a/third_party/terraform/tests/resource_compute_health_check_test.go +++ b/third_party/terraform/tests/resource_compute_health_check_test.go @@ -149,7 +149,7 @@ func TestAccComputeHealthCheck_tcpAndSsl_shouldFail(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccComputeHealthCheck_tcpAndSsl_shouldFail(hckName), - ExpectError: regexp.MustCompile("only one of `http2_health_check,http_health_check,https_health_check,ssl_health_check,tcp_health_check` can be specified"), + ExpectError: regexp.MustCompile("only one of `grpc_health_check,http2_health_check,http_health_check,https_health_check,ssl_health_check,tcp_health_check` can be specified"), }, }, }) diff --git a/third_party/terraform/tests/resource_compute_region_health_check_test.go.erb b/third_party/terraform/tests/resource_compute_region_health_check_test.go.erb index a7a3bf2fcf54..60dbf8fc9ada 100644 --- a/third_party/terraform/tests/resource_compute_region_health_check_test.go.erb +++ b/third_party/terraform/tests/resource_compute_region_health_check_test.go.erb @@ -156,7 +156,7 @@ func TestAccComputeRegionHealthCheck_tcpAndSsl_shouldFail(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccComputeRegionHealthCheck_tcpAndSsl_shouldFail(hckName), - ExpectError: regexp.MustCompile("only one of `http2_health_check,http_health_check,https_health_check,ssl_health_check,tcp_health_check` can be specified"), + ExpectError: regexp.MustCompile("only one of `grpc_health_check,http2_health_check,http_health_check,https_health_check,ssl_health_check,tcp_health_check` can be specified"), }, }, })