Skip to content

Commit 3e0dc96

Browse files
modular-magicianslevenick
authored andcommitted
Fix grpc healthcheck behaviour. (#3883) (#2404)
Signed-off-by: Modular Magician <[email protected]>
1 parent 8ab366b commit 3e0dc96

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

.changelog/3883.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
bug fix for an unreleased field
3+
```

google-beta/resource_compute_health_check.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,5 +2090,20 @@ func resourceComputeHealthCheckEncoder(d *schema.ResourceData, meta interface{},
20902090
return obj, nil
20912091
}
20922092

2093+
if _, ok := d.GetOk("grpc_health_check"); ok {
2094+
hc := d.Get("grpc_health_check").([]interface{})[0]
2095+
ps := hc.(map[string]interface{})["port_specification"]
2096+
pn := hc.(map[string]interface{})["port_name"]
2097+
2098+
if ps == "USE_FIXED_PORT" || (ps == "" && pn == "") {
2099+
m := obj["grpcHealthCheck"].(map[string]interface{})
2100+
if m["port"] == nil {
2101+
return nil, fmt.Errorf("error in HealthCheck %s: `port` must be set for GRPC health checks`.", d.Get("name").(string))
2102+
}
2103+
}
2104+
obj["type"] = "GRPC"
2105+
return obj, nil
2106+
}
2107+
20932108
return nil, fmt.Errorf("error in HealthCheck %s: No health check block specified.", d.Get("name").(string))
20942109
}

google-beta/resource_compute_health_check_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func TestAccComputeHealthCheck_tcpAndSsl_shouldFail(t *testing.T) {
149149
Steps: []resource.TestStep{
150150
{
151151
Config: testAccComputeHealthCheck_tcpAndSsl_shouldFail(hckName),
152-
ExpectError: regexp.MustCompile("only one of `http2_health_check,http_health_check,https_health_check,ssl_health_check,tcp_health_check` can be specified"),
152+
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"),
153153
},
154154
},
155155
})

google-beta/resource_compute_region_health_check.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,5 +2045,20 @@ func resourceComputeRegionHealthCheckEncoder(d *schema.ResourceData, meta interf
20452045
return obj, nil
20462046
}
20472047

2048+
if _, ok := d.GetOk("grpc_health_check"); ok {
2049+
hc := d.Get("grpc_health_check").([]interface{})[0]
2050+
ps := hc.(map[string]interface{})["port_specification"]
2051+
pn := hc.(map[string]interface{})["port_name"]
2052+
2053+
if ps == "USE_FIXED_PORT" || (ps == "" && pn == "") {
2054+
m := obj["grpcHealthCheck"].(map[string]interface{})
2055+
if m["port"] == nil {
2056+
return nil, fmt.Errorf("error in HealthCheck %s: `port` must be set for GRPC health checks`.", d.Get("name").(string))
2057+
}
2058+
}
2059+
obj["type"] = "GRPC"
2060+
return obj, nil
2061+
}
2062+
20482063
return nil, fmt.Errorf("error in HealthCheck %s: No health check block specified.", d.Get("name").(string))
20492064
}

google-beta/resource_compute_region_health_check_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func TestAccComputeRegionHealthCheck_tcpAndSsl_shouldFail(t *testing.T) {
154154
Steps: []resource.TestStep{
155155
{
156156
Config: testAccComputeRegionHealthCheck_tcpAndSsl_shouldFail(hckName),
157-
ExpectError: regexp.MustCompile("only one of `http2_health_check,http_health_check,https_health_check,ssl_health_check,tcp_health_check` can be specified"),
157+
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"),
158158
},
159159
},
160160
})

0 commit comments

Comments
 (0)