Skip to content

Commit

Permalink
Fix grpc healthcheck behaviour. (#3883) (#7061)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored and slevenick committed Aug 19, 2020
1 parent 62c1239 commit 16d7a50
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/3883.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none
bug fix for an unreleased field
```
15 changes: 15 additions & 0 deletions google/resource_compute_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -2018,5 +2018,20 @@ func resourceComputeHealthCheckEncoder(d *schema.ResourceData, meta interface{},
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))
}
2 changes: 1 addition & 1 deletion google/resource_compute_health_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
},
})
Expand Down
15 changes: 15 additions & 0 deletions google/resource_compute_region_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -1974,5 +1974,20 @@ func resourceComputeRegionHealthCheckEncoder(d *schema.ResourceData, meta interf
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))
}
2 changes: 1 addition & 1 deletion google/resource_compute_region_health_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,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"),
},
},
})
Expand Down

0 comments on commit 16d7a50

Please sign in to comment.