Skip to content

Commit

Permalink
Add RegionHealthCheck to compute (#168)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and Ty Larrabee committed Sep 16, 2019
1 parent 0e5aa87 commit f93c9cd
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions google/compute_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func healthCheckCustomizeDiff(diff *schema.ResourceDiff, v interface{}) error {
if diff.Get("https_health_check") != nil {
return validatePortSpec(diff, "https_health_check")
}
if diff.Get("http2_health_check") != nil {
return validatePortSpec(diff, "http2_health_check")
}
if diff.Get("tcp_health_check") != nil {
return validatePortSpec(diff, "tcp_health_check")
}
Expand All @@ -82,6 +85,8 @@ func portDiffSuppress(k, old, new string, _ *schema.ResourceData) bool {
defaultPort = 80
case "https_health_check":
defaultPort = 443
case "http2_health_check":
defaultPort = 443
case "tcp_health_check":
defaultPort = 80
case "ssl_health_check":
Expand Down Expand Up @@ -183,6 +188,12 @@ func GetComputeHealthCheckApiObject(d TerraformResourceData, config *Config) (ma
} else if v, ok := d.GetOkExists("ssl_health_check"); !isEmptyValue(reflect.ValueOf(sslHealthCheckProp)) && (ok || !reflect.DeepEqual(v, sslHealthCheckProp)) {
obj["sslHealthCheck"] = sslHealthCheckProp
}
http2HealthCheckProp, err := expandComputeHealthCheckHttp2HealthCheck(d.Get("http2_health_check"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("http2_health_check"); !isEmptyValue(reflect.ValueOf(http2HealthCheckProp)) && (ok || !reflect.DeepEqual(v, http2HealthCheckProp)) {
obj["http2HealthCheck"] = http2HealthCheckProp
}

return resourceComputeHealthCheckEncoder(d, config, obj)
}
Expand Down Expand Up @@ -215,6 +226,19 @@ func resourceComputeHealthCheckEncoder(d TerraformResourceData, meta interface{}
obj["type"] = "HTTPS"
return obj, nil
}
if _, ok := d.GetOk("http2_health_check"); ok {
hc := d.Get("http2_health_check").([]interface{})[0]
ps := hc.(map[string]interface{})["port_specification"]

if ps == "USE_FIXED_PORT" || ps == "" {
m := obj["http2HealthCheck"].(map[string]interface{})
if m["port"] == nil {
m["port"] = 443
}
}
obj["type"] = "HTTP2"
return obj, nil
}
if _, ok := d.GetOk("tcp_health_check"); ok {
hc := d.Get("tcp_health_check").([]interface{})[0]
ps := hc.(map[string]interface{})["port_specification"]
Expand Down Expand Up @@ -602,3 +626,92 @@ func expandComputeHealthCheckSslHealthCheckProxyHeader(v interface{}, d Terrafor
func expandComputeHealthCheckSslHealthCheckPortSpecification(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeHealthCheckHttp2HealthCheck(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedHost, err := expandComputeHealthCheckHttp2HealthCheckHost(original["host"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedHost); val.IsValid() && !isEmptyValue(val) {
transformed["host"] = transformedHost
}

transformedRequestPath, err := expandComputeHealthCheckHttp2HealthCheckRequestPath(original["request_path"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedRequestPath); val.IsValid() && !isEmptyValue(val) {
transformed["requestPath"] = transformedRequestPath
}

transformedResponse, err := expandComputeHealthCheckHttp2HealthCheckResponse(original["response"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedResponse); val.IsValid() && !isEmptyValue(val) {
transformed["response"] = transformedResponse
}

transformedPort, err := expandComputeHealthCheckHttp2HealthCheckPort(original["port"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPort); val.IsValid() && !isEmptyValue(val) {
transformed["port"] = transformedPort
}

transformedPortName, err := expandComputeHealthCheckHttp2HealthCheckPortName(original["port_name"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPortName); val.IsValid() && !isEmptyValue(val) {
transformed["portName"] = transformedPortName
}

transformedProxyHeader, err := expandComputeHealthCheckHttp2HealthCheckProxyHeader(original["proxy_header"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedProxyHeader); val.IsValid() && !isEmptyValue(val) {
transformed["proxyHeader"] = transformedProxyHeader
}

transformedPortSpecification, err := expandComputeHealthCheckHttp2HealthCheckPortSpecification(original["port_specification"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPortSpecification); val.IsValid() && !isEmptyValue(val) {
transformed["portSpecification"] = transformedPortSpecification
}

return transformed, nil
}

func expandComputeHealthCheckHttp2HealthCheckHost(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeHealthCheckHttp2HealthCheckRequestPath(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeHealthCheckHttp2HealthCheckResponse(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeHealthCheckHttp2HealthCheckPort(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeHealthCheckHttp2HealthCheckPortName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeHealthCheckHttp2HealthCheckProxyHeader(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeHealthCheckHttp2HealthCheckPortSpecification(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

0 comments on commit f93c9cd

Please sign in to comment.