2018-08-27 23:35:47 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// This file is automatically generated by Magic Modules and manual
|
|
|
|
// changes will be clobbered when the file is regenerated.
|
|
|
|
//
|
|
|
|
// Please read more about how to change this file in
|
|
|
|
// .github/CONTRIBUTING.md.
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2016-11-18 16:08:26 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2018-08-27 23:35:47 +00:00
|
|
|
"reflect"
|
|
|
|
"strconv"
|
|
|
|
"time"
|
2016-11-18 16:08:26 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
2018-08-27 23:35:47 +00:00
|
|
|
"github.com/hashicorp/terraform/helper/validation"
|
|
|
|
compute "google.golang.org/api/compute/v1"
|
2016-11-18 16:08:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func resourceComputeHealthCheck() *schema.Resource {
|
|
|
|
return &schema.Resource{
|
|
|
|
Create: resourceComputeHealthCheckCreate,
|
|
|
|
Read: resourceComputeHealthCheckRead,
|
|
|
|
Update: resourceComputeHealthCheckUpdate,
|
2018-08-27 23:35:47 +00:00
|
|
|
Delete: resourceComputeHealthCheckDelete,
|
|
|
|
|
2016-11-18 16:08:26 +00:00
|
|
|
Importer: &schema.ResourceImporter{
|
2018-08-27 23:35:47 +00:00
|
|
|
State: resourceComputeHealthCheckImport,
|
|
|
|
},
|
|
|
|
|
|
|
|
Timeouts: &schema.ResourceTimeout{
|
|
|
|
Create: schema.DefaultTimeout(240 * time.Second),
|
|
|
|
Update: schema.DefaultTimeout(240 * time.Second),
|
|
|
|
Delete: schema.DefaultTimeout(240 * time.Second),
|
2016-11-18 16:08:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Schema: map[string]*schema.Schema{
|
2018-08-27 23:35:47 +00:00
|
|
|
"name": {
|
2016-11-18 16:08:26 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
2018-08-27 23:35:47 +00:00
|
|
|
"check_interval_sec": {
|
2016-11-18 16:08:26 +00:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Optional: true,
|
|
|
|
Default: 5,
|
|
|
|
},
|
2018-08-27 23:35:47 +00:00
|
|
|
"description": {
|
2016-11-18 16:08:26 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
2018-08-27 23:35:47 +00:00
|
|
|
"healthy_threshold": {
|
2016-11-18 16:08:26 +00:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Optional: true,
|
|
|
|
Default: 2,
|
|
|
|
},
|
2018-08-27 23:35:47 +00:00
|
|
|
"http_health_check": {
|
|
|
|
Type: schema.TypeList,
|
|
|
|
Optional: true,
|
|
|
|
MaxItems: 1,
|
2016-11-18 16:08:26 +00:00
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2018-08-27 23:35:47 +00:00
|
|
|
"host": {
|
2016-11-18 16:08:26 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
2018-08-27 23:35:47 +00:00
|
|
|
"port": {
|
|
|
|
Type: schema.TypeInt,
|
2016-11-18 16:08:26 +00:00
|
|
|
Optional: true,
|
2018-08-27 23:35:47 +00:00
|
|
|
Default: 80,
|
|
|
|
},
|
|
|
|
"proxy_header": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ValidateFunc: validation.StringInSlice([]string{"NONE", "PROXY_V1", ""}, false),
|
|
|
|
Default: "NONE",
|
2016-11-18 16:08:26 +00:00
|
|
|
},
|
2018-09-20 20:22:36 +00:00
|
|
|
"request_path": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Default: "/",
|
|
|
|
},
|
2016-11-18 16:08:26 +00:00
|
|
|
},
|
|
|
|
},
|
2018-08-27 23:35:47 +00:00
|
|
|
ConflictsWith: []string{"https_health_check", "tcp_health_check", "ssl_health_check"},
|
2016-11-18 16:08:26 +00:00
|
|
|
},
|
2018-08-27 23:35:47 +00:00
|
|
|
"https_health_check": {
|
|
|
|
Type: schema.TypeList,
|
|
|
|
Optional: true,
|
|
|
|
MaxItems: 1,
|
2016-11-30 00:08:44 +00:00
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2018-08-27 23:35:47 +00:00
|
|
|
"host": {
|
2016-11-30 00:08:44 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
2018-08-27 23:35:47 +00:00
|
|
|
"port": {
|
|
|
|
Type: schema.TypeInt,
|
2016-11-30 00:08:44 +00:00
|
|
|
Optional: true,
|
2018-08-27 23:35:47 +00:00
|
|
|
Default: 443,
|
|
|
|
},
|
|
|
|
"proxy_header": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ValidateFunc: validation.StringInSlice([]string{"NONE", "PROXY_V1", ""}, false),
|
|
|
|
Default: "NONE",
|
2016-11-30 00:08:44 +00:00
|
|
|
},
|
2018-09-20 20:22:36 +00:00
|
|
|
"request_path": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Default: "/",
|
|
|
|
},
|
2016-11-30 00:08:44 +00:00
|
|
|
},
|
|
|
|
},
|
2018-08-27 23:35:47 +00:00
|
|
|
ConflictsWith: []string{"http_health_check", "tcp_health_check", "ssl_health_check"},
|
2016-11-30 00:08:44 +00:00
|
|
|
},
|
2018-09-20 20:22:36 +00:00
|
|
|
"ssl_health_check": {
|
2018-08-27 23:35:47 +00:00
|
|
|
Type: schema.TypeList,
|
|
|
|
Optional: true,
|
|
|
|
MaxItems: 1,
|
2016-11-30 00:08:44 +00:00
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2018-08-27 23:35:47 +00:00
|
|
|
"port": {
|
|
|
|
Type: schema.TypeInt,
|
2016-11-30 00:08:44 +00:00
|
|
|
Optional: true,
|
2018-09-20 20:22:36 +00:00
|
|
|
Default: 443,
|
2018-08-27 23:35:47 +00:00
|
|
|
},
|
|
|
|
"proxy_header": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ValidateFunc: validation.StringInSlice([]string{"NONE", "PROXY_V1", ""}, false),
|
|
|
|
Default: "NONE",
|
2016-11-30 00:08:44 +00:00
|
|
|
},
|
2018-08-27 23:35:47 +00:00
|
|
|
"request": {
|
2016-11-30 00:08:44 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
2018-08-27 23:35:47 +00:00
|
|
|
"response": {
|
2016-11-30 00:08:44 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
2018-09-20 20:22:36 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
ConflictsWith: []string{"http_health_check", "https_health_check", "tcp_health_check"},
|
|
|
|
},
|
|
|
|
"tcp_health_check": {
|
|
|
|
Type: schema.TypeList,
|
|
|
|
Optional: true,
|
|
|
|
MaxItems: 1,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2018-08-27 23:35:47 +00:00
|
|
|
"port": {
|
|
|
|
Type: schema.TypeInt,
|
2016-11-30 00:08:44 +00:00
|
|
|
Optional: true,
|
2018-09-20 20:22:36 +00:00
|
|
|
Default: 80,
|
2018-08-27 23:35:47 +00:00
|
|
|
},
|
|
|
|
"proxy_header": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ValidateFunc: validation.StringInSlice([]string{"NONE", "PROXY_V1", ""}, false),
|
|
|
|
Default: "NONE",
|
2016-11-30 00:08:44 +00:00
|
|
|
},
|
2018-09-20 20:22:36 +00:00
|
|
|
"request": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
|
|
|
"response": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
2016-11-30 00:08:44 +00:00
|
|
|
},
|
|
|
|
},
|
2018-09-20 20:22:36 +00:00
|
|
|
ConflictsWith: []string{"http_health_check", "https_health_check", "ssl_health_check"},
|
|
|
|
},
|
|
|
|
"timeout_sec": {
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
Optional: true,
|
|
|
|
Default: 5,
|
|
|
|
},
|
|
|
|
"unhealthy_threshold": {
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
Optional: true,
|
|
|
|
Default: 2,
|
2016-11-30 00:08:44 +00:00
|
|
|
},
|
2018-08-27 23:35:47 +00:00
|
|
|
"creation_timestamp": {
|
2016-11-18 16:08:26 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2018-08-27 23:35:47 +00:00
|
|
|
"type": {
|
2016-11-18 16:08:26 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2018-08-27 23:35:47 +00:00
|
|
|
"project": {
|
|
|
|
Type: schema.TypeString,
|
2016-11-18 16:08:26 +00:00
|
|
|
Optional: true,
|
2018-08-27 23:35:47 +00:00
|
|
|
Computed: true,
|
|
|
|
ForceNew: true,
|
2016-11-18 16:08:26 +00:00
|
|
|
},
|
2018-08-27 23:35:47 +00:00
|
|
|
"self_link": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
2016-11-18 16:08:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceComputeHealthCheckCreate(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
config := meta.(*Config)
|
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
obj := make(map[string]interface{})
|
|
|
|
checkIntervalSecProp, err := expandComputeHealthCheckCheckIntervalSec(d.Get("check_interval_sec"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("check_interval_sec"); !isEmptyValue(reflect.ValueOf(checkIntervalSecProp)) && (ok || !reflect.DeepEqual(v, checkIntervalSecProp)) {
|
|
|
|
obj["checkIntervalSec"] = checkIntervalSecProp
|
|
|
|
}
|
|
|
|
descriptionProp, err := expandComputeHealthCheckDescription(d.Get("description"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
|
|
|
|
obj["description"] = descriptionProp
|
|
|
|
}
|
|
|
|
healthyThresholdProp, err := expandComputeHealthCheckHealthyThreshold(d.Get("healthy_threshold"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("healthy_threshold"); !isEmptyValue(reflect.ValueOf(healthyThresholdProp)) && (ok || !reflect.DeepEqual(v, healthyThresholdProp)) {
|
|
|
|
obj["healthyThreshold"] = healthyThresholdProp
|
|
|
|
}
|
|
|
|
nameProp, err := expandComputeHealthCheckName(d.Get("name"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) {
|
|
|
|
obj["name"] = nameProp
|
|
|
|
}
|
|
|
|
timeoutSecProp, err := expandComputeHealthCheckTimeoutSec(d.Get("timeout_sec"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("timeout_sec"); !isEmptyValue(reflect.ValueOf(timeoutSecProp)) && (ok || !reflect.DeepEqual(v, timeoutSecProp)) {
|
|
|
|
obj["timeoutSec"] = timeoutSecProp
|
|
|
|
}
|
|
|
|
unhealthyThresholdProp, err := expandComputeHealthCheckUnhealthyThreshold(d.Get("unhealthy_threshold"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("unhealthy_threshold"); !isEmptyValue(reflect.ValueOf(unhealthyThresholdProp)) && (ok || !reflect.DeepEqual(v, unhealthyThresholdProp)) {
|
|
|
|
obj["unhealthyThreshold"] = unhealthyThresholdProp
|
|
|
|
}
|
|
|
|
httpHealthCheckProp, err := expandComputeHealthCheckHttpHealthCheck(d.Get("http_health_check"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("http_health_check"); !isEmptyValue(reflect.ValueOf(httpHealthCheckProp)) && (ok || !reflect.DeepEqual(v, httpHealthCheckProp)) {
|
|
|
|
obj["httpHealthCheck"] = httpHealthCheckProp
|
|
|
|
}
|
|
|
|
httpsHealthCheckProp, err := expandComputeHealthCheckHttpsHealthCheck(d.Get("https_health_check"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("https_health_check"); !isEmptyValue(reflect.ValueOf(httpsHealthCheckProp)) && (ok || !reflect.DeepEqual(v, httpsHealthCheckProp)) {
|
|
|
|
obj["httpsHealthCheck"] = httpsHealthCheckProp
|
|
|
|
}
|
|
|
|
tcpHealthCheckProp, err := expandComputeHealthCheckTcpHealthCheck(d.Get("tcp_health_check"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("tcp_health_check"); !isEmptyValue(reflect.ValueOf(tcpHealthCheckProp)) && (ok || !reflect.DeepEqual(v, tcpHealthCheckProp)) {
|
|
|
|
obj["tcpHealthCheck"] = tcpHealthCheckProp
|
|
|
|
}
|
|
|
|
sslHealthCheckProp, err := expandComputeHealthCheckSslHealthCheck(d.Get("ssl_health_check"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("ssl_health_check"); !isEmptyValue(reflect.ValueOf(sslHealthCheckProp)) && (ok || !reflect.DeepEqual(v, sslHealthCheckProp)) {
|
|
|
|
obj["sslHealthCheck"] = sslHealthCheckProp
|
|
|
|
}
|
|
|
|
|
|
|
|
obj, err = resourceComputeHealthCheckEncoder(d, meta, obj)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/healthChecks")
|
2016-11-18 16:08:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
log.Printf("[DEBUG] Creating new HealthCheck: %#v", obj)
|
|
|
|
res, err := sendRequest(config, "POST", url, obj)
|
2016-11-18 16:08:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error creating HealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
// Store the ID now
|
|
|
|
id, err := replaceVars(d, config, "{{name}}")
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error constructing id: %s", err)
|
|
|
|
}
|
|
|
|
d.SetId(id)
|
2016-11-18 16:08:26 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
project, err := getProject(d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
op := &compute.Operation{}
|
|
|
|
err = Convert(res, op)
|
2016-11-18 16:08:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
waitErr := computeOperationWaitTime(
|
|
|
|
config.clientCompute, op, project, "Creating HealthCheck",
|
|
|
|
int(d.Timeout(schema.TimeoutCreate).Minutes()))
|
|
|
|
|
|
|
|
if waitErr != nil {
|
|
|
|
// The resource didn't actually create
|
|
|
|
d.SetId("")
|
|
|
|
return fmt.Errorf("Error waiting to create HealthCheck: %s", waitErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("[DEBUG] Finished creating HealthCheck %q: %#v", d.Id(), res)
|
|
|
|
|
2016-11-18 16:08:26 +00:00
|
|
|
return resourceComputeHealthCheckRead(d, meta)
|
|
|
|
}
|
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
func resourceComputeHealthCheckRead(d *schema.ResourceData, meta interface{}) error {
|
2016-11-18 16:08:26 +00:00
|
|
|
config := meta.(*Config)
|
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/healthChecks/{{name}}")
|
2016-11-18 16:08:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
res, err := sendRequest(config, "GET", url, nil)
|
|
|
|
if err != nil {
|
|
|
|
return handleNotFoundError(err, d, fmt.Sprintf("ComputeHealthCheck %q", d.Id()))
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := d.Set("check_interval_sec", flattenComputeHealthCheckCheckIntervalSec(res["checkIntervalSec"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("creation_timestamp", flattenComputeHealthCheckCreationTimestamp(res["creationTimestamp"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("description", flattenComputeHealthCheckDescription(res["description"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("healthy_threshold", flattenComputeHealthCheckHealthyThreshold(res["healthyThreshold"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("name", flattenComputeHealthCheckName(res["name"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("timeout_sec", flattenComputeHealthCheckTimeoutSec(res["timeoutSec"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("unhealthy_threshold", flattenComputeHealthCheckUnhealthyThreshold(res["unhealthyThreshold"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("type", flattenComputeHealthCheckType(res["type"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("http_health_check", flattenComputeHealthCheckHttpHealthCheck(res["httpHealthCheck"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("https_health_check", flattenComputeHealthCheckHttpsHealthCheck(res["httpsHealthCheck"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("tcp_health_check", flattenComputeHealthCheckTcpHealthCheck(res["tcpHealthCheck"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("ssl_health_check", flattenComputeHealthCheckSslHealthCheck(res["sslHealthCheck"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
project, err := getProject(d, config)
|
2016-11-18 16:08:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-27 23:35:47 +00:00
|
|
|
if err := d.Set("project", project); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HealthCheck: %s", err)
|
|
|
|
}
|
2016-11-18 16:08:26 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
return nil
|
2016-11-18 16:08:26 +00:00
|
|
|
}
|
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
func resourceComputeHealthCheckUpdate(d *schema.ResourceData, meta interface{}) error {
|
2016-11-18 16:08:26 +00:00
|
|
|
config := meta.(*Config)
|
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
obj := make(map[string]interface{})
|
|
|
|
checkIntervalSecProp, err := expandComputeHealthCheckCheckIntervalSec(d.Get("check_interval_sec"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("check_interval_sec"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, checkIntervalSecProp)) {
|
|
|
|
obj["checkIntervalSec"] = checkIntervalSecProp
|
|
|
|
}
|
|
|
|
descriptionProp, err := expandComputeHealthCheckDescription(d.Get("description"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
|
|
|
|
obj["description"] = descriptionProp
|
|
|
|
}
|
|
|
|
healthyThresholdProp, err := expandComputeHealthCheckHealthyThreshold(d.Get("healthy_threshold"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("healthy_threshold"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, healthyThresholdProp)) {
|
|
|
|
obj["healthyThreshold"] = healthyThresholdProp
|
|
|
|
}
|
|
|
|
nameProp, err := expandComputeHealthCheckName(d.Get("name"), d, config)
|
2016-11-18 16:08:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-08-27 23:35:47 +00:00
|
|
|
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) {
|
|
|
|
obj["name"] = nameProp
|
2016-11-18 16:08:26 +00:00
|
|
|
}
|
2018-08-27 23:35:47 +00:00
|
|
|
timeoutSecProp, err := expandComputeHealthCheckTimeoutSec(d.Get("timeout_sec"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("timeout_sec"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, timeoutSecProp)) {
|
|
|
|
obj["timeoutSec"] = timeoutSecProp
|
|
|
|
}
|
|
|
|
unhealthyThresholdProp, err := expandComputeHealthCheckUnhealthyThreshold(d.Get("unhealthy_threshold"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("unhealthy_threshold"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, unhealthyThresholdProp)) {
|
|
|
|
obj["unhealthyThreshold"] = unhealthyThresholdProp
|
|
|
|
}
|
|
|
|
httpHealthCheckProp, err := expandComputeHealthCheckHttpHealthCheck(d.Get("http_health_check"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("http_health_check"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, httpHealthCheckProp)) {
|
|
|
|
obj["httpHealthCheck"] = httpHealthCheckProp
|
|
|
|
}
|
|
|
|
httpsHealthCheckProp, err := expandComputeHealthCheckHttpsHealthCheck(d.Get("https_health_check"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("https_health_check"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, httpsHealthCheckProp)) {
|
|
|
|
obj["httpsHealthCheck"] = httpsHealthCheckProp
|
|
|
|
}
|
|
|
|
tcpHealthCheckProp, err := expandComputeHealthCheckTcpHealthCheck(d.Get("tcp_health_check"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("tcp_health_check"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, tcpHealthCheckProp)) {
|
|
|
|
obj["tcpHealthCheck"] = tcpHealthCheckProp
|
|
|
|
}
|
|
|
|
sslHealthCheckProp, err := expandComputeHealthCheckSslHealthCheck(d.Get("ssl_health_check"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if v, ok := d.GetOkExists("ssl_health_check"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, sslHealthCheckProp)) {
|
|
|
|
obj["sslHealthCheck"] = sslHealthCheckProp
|
|
|
|
}
|
|
|
|
|
|
|
|
obj, err = resourceComputeHealthCheckEncoder(d, meta, obj)
|
2016-11-18 16:08:26 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/healthChecks/{{name}}")
|
2016-11-18 16:08:26 +00:00
|
|
|
if err != nil {
|
2018-08-27 23:35:47 +00:00
|
|
|
return err
|
2016-11-18 16:08:26 +00:00
|
|
|
}
|
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
log.Printf("[DEBUG] Updating HealthCheck %q: %#v", d.Id(), obj)
|
|
|
|
res, err := sendRequest(config, "PUT", url, obj)
|
2016-11-18 16:08:26 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error updating HealthCheck %q: %s", d.Id(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
project, err := getProject(d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
op := &compute.Operation{}
|
|
|
|
err = Convert(res, op)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = computeOperationWaitTime(
|
|
|
|
config.clientCompute, op, project, "Updating HealthCheck",
|
|
|
|
int(d.Timeout(schema.TimeoutUpdate).Minutes()))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return resourceComputeHealthCheckRead(d, meta)
|
2016-11-18 16:08:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func resourceComputeHealthCheckDelete(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
config := meta.(*Config)
|
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/healthChecks/{{name}}")
|
2016-11-18 16:08:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
var obj map[string]interface{}
|
|
|
|
log.Printf("[DEBUG] Deleting HealthCheck %q", d.Id())
|
|
|
|
res, err := sendRequest(config, "DELETE", url, obj)
|
2016-11-18 16:08:26 +00:00
|
|
|
if err != nil {
|
2018-08-27 23:35:47 +00:00
|
|
|
return handleNotFoundError(err, d, "HealthCheck")
|
2016-11-18 16:08:26 +00:00
|
|
|
}
|
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
project, err := getProject(d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
op := &compute.Operation{}
|
|
|
|
err = Convert(res, op)
|
2016-11-18 16:08:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
err = computeOperationWaitTime(
|
|
|
|
config.clientCompute, op, project, "Deleting HealthCheck",
|
|
|
|
int(d.Timeout(schema.TimeoutDelete).Minutes()))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("[DEBUG] Finished deleting HealthCheck %q: %#v", d.Id(), res)
|
2016-11-18 16:08:26 +00:00
|
|
|
return nil
|
|
|
|
}
|
2017-06-26 15:25:22 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
func resourceComputeHealthCheckImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
|
|
|
|
config := meta.(*Config)
|
|
|
|
parseImportId([]string{"projects/(?P<project>[^/]+)/global/healthChecks/(?P<name>[^/]+)", "(?P<project>[^/]+)/(?P<name>[^/]+)", "(?P<name>[^/]+)"}, d, config)
|
|
|
|
|
|
|
|
// Replace import id for the resource id
|
|
|
|
id, err := replaceVars(d, config, "{{name}}")
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error constructing id: %s", err)
|
|
|
|
}
|
|
|
|
d.SetId(id)
|
|
|
|
|
|
|
|
return []*schema.ResourceData{d}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHealthCheckCheckIntervalSec(v interface{}) interface{} {
|
|
|
|
// Handles the string fixed64 format
|
|
|
|
if strVal, ok := v.(string); ok {
|
|
|
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
|
|
|
return intVal
|
|
|
|
} // let terraform core handle it if we can't convert the string to an int.
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHealthCheckCreationTimestamp(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHealthCheckDescription(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHealthCheckHealthyThreshold(v interface{}) interface{} {
|
|
|
|
// Handles the string fixed64 format
|
|
|
|
if strVal, ok := v.(string); ok {
|
|
|
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
|
|
|
return intVal
|
|
|
|
} // let terraform core handle it if we can't convert the string to an int.
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHealthCheckName(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHealthCheckTimeoutSec(v interface{}) interface{} {
|
|
|
|
// Handles the string fixed64 format
|
|
|
|
if strVal, ok := v.(string); ok {
|
|
|
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
|
|
|
return intVal
|
|
|
|
} // let terraform core handle it if we can't convert the string to an int.
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHealthCheckUnhealthyThreshold(v interface{}) interface{} {
|
|
|
|
// Handles the string fixed64 format
|
|
|
|
if strVal, ok := v.(string); ok {
|
|
|
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
|
|
|
return intVal
|
|
|
|
} // let terraform core handle it if we can't convert the string to an int.
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHealthCheckType(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHealthCheckHttpHealthCheck(v interface{}) interface{} {
|
|
|
|
if v == nil {
|
2017-06-26 15:25:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
2018-08-27 23:35:47 +00:00
|
|
|
original := v.(map[string]interface{})
|
2018-11-16 20:45:58 +00:00
|
|
|
if len(original) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2018-08-27 23:35:47 +00:00
|
|
|
transformed := make(map[string]interface{})
|
|
|
|
transformed["host"] =
|
|
|
|
flattenComputeHealthCheckHttpHealthCheckHost(original["host"])
|
|
|
|
transformed["request_path"] =
|
|
|
|
flattenComputeHealthCheckHttpHealthCheckRequestPath(original["requestPath"])
|
|
|
|
transformed["port"] =
|
|
|
|
flattenComputeHealthCheckHttpHealthCheckPort(original["port"])
|
|
|
|
transformed["proxy_header"] =
|
|
|
|
flattenComputeHealthCheckHttpHealthCheckProxyHeader(original["proxyHeader"])
|
|
|
|
return []interface{}{transformed}
|
|
|
|
}
|
|
|
|
func flattenComputeHealthCheckHttpHealthCheckHost(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
2017-06-26 15:25:22 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
func flattenComputeHealthCheckHttpHealthCheckRequestPath(v interface{}) interface{} {
|
|
|
|
return v
|
2017-06-26 15:25:22 +00:00
|
|
|
}
|
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
func flattenComputeHealthCheckHttpHealthCheckPort(v interface{}) interface{} {
|
|
|
|
// Handles the string fixed64 format
|
|
|
|
if strVal, ok := v.(string); ok {
|
|
|
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
|
|
|
return intVal
|
|
|
|
} // let terraform core handle it if we can't convert the string to an int.
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHealthCheckHttpHealthCheckProxyHeader(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHealthCheckHttpsHealthCheck(v interface{}) interface{} {
|
|
|
|
if v == nil {
|
2017-06-26 15:25:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
2018-08-27 23:35:47 +00:00
|
|
|
original := v.(map[string]interface{})
|
2018-11-16 20:45:58 +00:00
|
|
|
if len(original) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2018-08-27 23:35:47 +00:00
|
|
|
transformed := make(map[string]interface{})
|
|
|
|
transformed["host"] =
|
|
|
|
flattenComputeHealthCheckHttpsHealthCheckHost(original["host"])
|
|
|
|
transformed["request_path"] =
|
|
|
|
flattenComputeHealthCheckHttpsHealthCheckRequestPath(original["requestPath"])
|
|
|
|
transformed["port"] =
|
|
|
|
flattenComputeHealthCheckHttpsHealthCheckPort(original["port"])
|
|
|
|
transformed["proxy_header"] =
|
|
|
|
flattenComputeHealthCheckHttpsHealthCheckProxyHeader(original["proxyHeader"])
|
|
|
|
return []interface{}{transformed}
|
|
|
|
}
|
|
|
|
func flattenComputeHealthCheckHttpsHealthCheckHost(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
2017-06-26 15:25:22 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
func flattenComputeHealthCheckHttpsHealthCheckRequestPath(v interface{}) interface{} {
|
|
|
|
return v
|
2017-06-26 15:25:22 +00:00
|
|
|
}
|
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
func flattenComputeHealthCheckHttpsHealthCheckPort(v interface{}) interface{} {
|
|
|
|
// Handles the string fixed64 format
|
|
|
|
if strVal, ok := v.(string); ok {
|
|
|
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
|
|
|
return intVal
|
|
|
|
} // let terraform core handle it if we can't convert the string to an int.
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHealthCheckHttpsHealthCheckProxyHeader(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHealthCheckTcpHealthCheck(v interface{}) interface{} {
|
|
|
|
if v == nil {
|
2017-06-26 15:25:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
2018-08-27 23:35:47 +00:00
|
|
|
original := v.(map[string]interface{})
|
2018-11-16 20:45:58 +00:00
|
|
|
if len(original) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2018-08-27 23:35:47 +00:00
|
|
|
transformed := make(map[string]interface{})
|
|
|
|
transformed["request"] =
|
|
|
|
flattenComputeHealthCheckTcpHealthCheckRequest(original["request"])
|
|
|
|
transformed["response"] =
|
|
|
|
flattenComputeHealthCheckTcpHealthCheckResponse(original["response"])
|
|
|
|
transformed["port"] =
|
|
|
|
flattenComputeHealthCheckTcpHealthCheckPort(original["port"])
|
|
|
|
transformed["proxy_header"] =
|
|
|
|
flattenComputeHealthCheckTcpHealthCheckProxyHeader(original["proxyHeader"])
|
|
|
|
return []interface{}{transformed}
|
|
|
|
}
|
|
|
|
func flattenComputeHealthCheckTcpHealthCheckRequest(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHealthCheckTcpHealthCheckResponse(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHealthCheckTcpHealthCheckPort(v interface{}) interface{} {
|
|
|
|
// Handles the string fixed64 format
|
|
|
|
if strVal, ok := v.(string); ok {
|
|
|
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
|
|
|
return intVal
|
|
|
|
} // let terraform core handle it if we can't convert the string to an int.
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
2017-06-26 15:25:22 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
func flattenComputeHealthCheckTcpHealthCheckProxyHeader(v interface{}) interface{} {
|
|
|
|
return v
|
2017-06-26 15:25:22 +00:00
|
|
|
}
|
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
func flattenComputeHealthCheckSslHealthCheck(v interface{}) interface{} {
|
|
|
|
if v == nil {
|
2017-06-26 15:25:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
2018-08-27 23:35:47 +00:00
|
|
|
original := v.(map[string]interface{})
|
2018-11-16 20:45:58 +00:00
|
|
|
if len(original) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2018-08-27 23:35:47 +00:00
|
|
|
transformed := make(map[string]interface{})
|
|
|
|
transformed["request"] =
|
|
|
|
flattenComputeHealthCheckSslHealthCheckRequest(original["request"])
|
|
|
|
transformed["response"] =
|
|
|
|
flattenComputeHealthCheckSslHealthCheckResponse(original["response"])
|
|
|
|
transformed["port"] =
|
|
|
|
flattenComputeHealthCheckSslHealthCheckPort(original["port"])
|
|
|
|
transformed["proxy_header"] =
|
|
|
|
flattenComputeHealthCheckSslHealthCheckProxyHeader(original["proxyHeader"])
|
|
|
|
return []interface{}{transformed}
|
|
|
|
}
|
|
|
|
func flattenComputeHealthCheckSslHealthCheckRequest(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHealthCheckSslHealthCheckResponse(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHealthCheckSslHealthCheckPort(v interface{}) interface{} {
|
|
|
|
// Handles the string fixed64 format
|
|
|
|
if strVal, ok := v.(string); ok {
|
|
|
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
|
|
|
return intVal
|
|
|
|
} // let terraform core handle it if we can't convert the string to an int.
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHealthCheckSslHealthCheckProxyHeader(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckCheckIntervalSec(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckDescription(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckHealthyThreshold(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckTimeoutSec(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckUnhealthyThreshold(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckHttpHealthCheck(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
l := v.([]interface{})
|
2018-10-11 19:57:31 +00:00
|
|
|
if len(l) == 0 || l[0] == nil {
|
2018-08-27 23:35:47 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
raw := l[0]
|
|
|
|
original := raw.(map[string]interface{})
|
|
|
|
transformed := make(map[string]interface{})
|
|
|
|
|
|
|
|
transformedHost, err := expandComputeHealthCheckHttpHealthCheckHost(original["host"], d, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-09-28 16:47:20 +00:00
|
|
|
} else if val := reflect.ValueOf(transformedHost); val.IsValid() && !isEmptyValue(val) {
|
|
|
|
transformed["host"] = transformedHost
|
2018-08-27 23:35:47 +00:00
|
|
|
}
|
2018-09-28 16:47:20 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
transformedRequestPath, err := expandComputeHealthCheckHttpHealthCheckRequestPath(original["request_path"], d, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-09-28 16:47:20 +00:00
|
|
|
} else if val := reflect.ValueOf(transformedRequestPath); val.IsValid() && !isEmptyValue(val) {
|
|
|
|
transformed["requestPath"] = transformedRequestPath
|
2018-08-27 23:35:47 +00:00
|
|
|
}
|
2018-09-28 16:47:20 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
transformedPort, err := expandComputeHealthCheckHttpHealthCheckPort(original["port"], d, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-09-28 16:47:20 +00:00
|
|
|
} else if val := reflect.ValueOf(transformedPort); val.IsValid() && !isEmptyValue(val) {
|
|
|
|
transformed["port"] = transformedPort
|
2018-08-27 23:35:47 +00:00
|
|
|
}
|
2018-09-28 16:47:20 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
transformedProxyHeader, err := expandComputeHealthCheckHttpHealthCheckProxyHeader(original["proxy_header"], d, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-09-28 16:47:20 +00:00
|
|
|
} else if val := reflect.ValueOf(transformedProxyHeader); val.IsValid() && !isEmptyValue(val) {
|
|
|
|
transformed["proxyHeader"] = transformedProxyHeader
|
2018-08-27 23:35:47 +00:00
|
|
|
}
|
2018-09-28 16:47:20 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
return transformed, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckHttpHealthCheckHost(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckHttpHealthCheckRequestPath(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckHttpHealthCheckPort(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckHttpHealthCheckProxyHeader(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckHttpsHealthCheck(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
l := v.([]interface{})
|
2018-10-11 19:57:31 +00:00
|
|
|
if len(l) == 0 || l[0] == nil {
|
2018-08-27 23:35:47 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
raw := l[0]
|
|
|
|
original := raw.(map[string]interface{})
|
|
|
|
transformed := make(map[string]interface{})
|
|
|
|
|
|
|
|
transformedHost, err := expandComputeHealthCheckHttpsHealthCheckHost(original["host"], d, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-09-28 16:47:20 +00:00
|
|
|
} else if val := reflect.ValueOf(transformedHost); val.IsValid() && !isEmptyValue(val) {
|
|
|
|
transformed["host"] = transformedHost
|
2018-08-27 23:35:47 +00:00
|
|
|
}
|
2018-09-28 16:47:20 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
transformedRequestPath, err := expandComputeHealthCheckHttpsHealthCheckRequestPath(original["request_path"], d, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-09-28 16:47:20 +00:00
|
|
|
} else if val := reflect.ValueOf(transformedRequestPath); val.IsValid() && !isEmptyValue(val) {
|
|
|
|
transformed["requestPath"] = transformedRequestPath
|
2018-08-27 23:35:47 +00:00
|
|
|
}
|
2018-09-28 16:47:20 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
transformedPort, err := expandComputeHealthCheckHttpsHealthCheckPort(original["port"], d, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-09-28 16:47:20 +00:00
|
|
|
} else if val := reflect.ValueOf(transformedPort); val.IsValid() && !isEmptyValue(val) {
|
|
|
|
transformed["port"] = transformedPort
|
2018-08-27 23:35:47 +00:00
|
|
|
}
|
2018-09-28 16:47:20 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
transformedProxyHeader, err := expandComputeHealthCheckHttpsHealthCheckProxyHeader(original["proxy_header"], d, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-09-28 16:47:20 +00:00
|
|
|
} else if val := reflect.ValueOf(transformedProxyHeader); val.IsValid() && !isEmptyValue(val) {
|
|
|
|
transformed["proxyHeader"] = transformedProxyHeader
|
2018-08-27 23:35:47 +00:00
|
|
|
}
|
2018-09-28 16:47:20 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
return transformed, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckHttpsHealthCheckHost(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckHttpsHealthCheckRequestPath(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckHttpsHealthCheckPort(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckHttpsHealthCheckProxyHeader(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckTcpHealthCheck(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
l := v.([]interface{})
|
2018-10-11 19:57:31 +00:00
|
|
|
if len(l) == 0 || l[0] == nil {
|
2018-08-27 23:35:47 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
raw := l[0]
|
|
|
|
original := raw.(map[string]interface{})
|
|
|
|
transformed := make(map[string]interface{})
|
|
|
|
|
|
|
|
transformedRequest, err := expandComputeHealthCheckTcpHealthCheckRequest(original["request"], d, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-09-28 16:47:20 +00:00
|
|
|
} else if val := reflect.ValueOf(transformedRequest); val.IsValid() && !isEmptyValue(val) {
|
|
|
|
transformed["request"] = transformedRequest
|
2018-08-27 23:35:47 +00:00
|
|
|
}
|
2018-09-28 16:47:20 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
transformedResponse, err := expandComputeHealthCheckTcpHealthCheckResponse(original["response"], d, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-09-28 16:47:20 +00:00
|
|
|
} else if val := reflect.ValueOf(transformedResponse); val.IsValid() && !isEmptyValue(val) {
|
|
|
|
transformed["response"] = transformedResponse
|
2018-08-27 23:35:47 +00:00
|
|
|
}
|
2018-09-28 16:47:20 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
transformedPort, err := expandComputeHealthCheckTcpHealthCheckPort(original["port"], d, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-09-28 16:47:20 +00:00
|
|
|
} else if val := reflect.ValueOf(transformedPort); val.IsValid() && !isEmptyValue(val) {
|
|
|
|
transformed["port"] = transformedPort
|
2018-08-27 23:35:47 +00:00
|
|
|
}
|
2018-09-28 16:47:20 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
transformedProxyHeader, err := expandComputeHealthCheckTcpHealthCheckProxyHeader(original["proxy_header"], d, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-09-28 16:47:20 +00:00
|
|
|
} else if val := reflect.ValueOf(transformedProxyHeader); val.IsValid() && !isEmptyValue(val) {
|
|
|
|
transformed["proxyHeader"] = transformedProxyHeader
|
2018-08-27 23:35:47 +00:00
|
|
|
}
|
2018-09-28 16:47:20 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
return transformed, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckTcpHealthCheckRequest(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckTcpHealthCheckResponse(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckTcpHealthCheckPort(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckTcpHealthCheckProxyHeader(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckSslHealthCheck(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
l := v.([]interface{})
|
2018-10-11 19:57:31 +00:00
|
|
|
if len(l) == 0 || l[0] == nil {
|
2018-08-27 23:35:47 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
raw := l[0]
|
|
|
|
original := raw.(map[string]interface{})
|
|
|
|
transformed := make(map[string]interface{})
|
|
|
|
|
|
|
|
transformedRequest, err := expandComputeHealthCheckSslHealthCheckRequest(original["request"], d, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-09-28 16:47:20 +00:00
|
|
|
} else if val := reflect.ValueOf(transformedRequest); val.IsValid() && !isEmptyValue(val) {
|
|
|
|
transformed["request"] = transformedRequest
|
2018-08-27 23:35:47 +00:00
|
|
|
}
|
2018-09-28 16:47:20 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
transformedResponse, err := expandComputeHealthCheckSslHealthCheckResponse(original["response"], d, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-09-28 16:47:20 +00:00
|
|
|
} else if val := reflect.ValueOf(transformedResponse); val.IsValid() && !isEmptyValue(val) {
|
|
|
|
transformed["response"] = transformedResponse
|
2018-08-27 23:35:47 +00:00
|
|
|
}
|
2018-09-28 16:47:20 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
transformedPort, err := expandComputeHealthCheckSslHealthCheckPort(original["port"], d, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-09-28 16:47:20 +00:00
|
|
|
} else if val := reflect.ValueOf(transformedPort); val.IsValid() && !isEmptyValue(val) {
|
|
|
|
transformed["port"] = transformedPort
|
2018-08-27 23:35:47 +00:00
|
|
|
}
|
2018-09-28 16:47:20 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
transformedProxyHeader, err := expandComputeHealthCheckSslHealthCheckProxyHeader(original["proxy_header"], d, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-09-28 16:47:20 +00:00
|
|
|
} else if val := reflect.ValueOf(transformedProxyHeader); val.IsValid() && !isEmptyValue(val) {
|
|
|
|
transformed["proxyHeader"] = transformedProxyHeader
|
2018-08-27 23:35:47 +00:00
|
|
|
}
|
2018-09-28 16:47:20 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
return transformed, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckSslHealthCheckRequest(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckSslHealthCheckResponse(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckSslHealthCheckPort(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHealthCheckSslHealthCheckProxyHeader(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceComputeHealthCheckEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
|
|
|
|
if _, ok := d.GetOk("http_health_check"); ok {
|
|
|
|
obj["type"] = "HTTP"
|
|
|
|
return obj, nil
|
|
|
|
}
|
|
|
|
if _, ok := d.GetOk("https_health_check"); ok {
|
|
|
|
obj["type"] = "HTTPS"
|
|
|
|
return obj, nil
|
|
|
|
}
|
|
|
|
if _, ok := d.GetOk("tcp_health_check"); ok {
|
|
|
|
obj["type"] = "TCP"
|
|
|
|
return obj, nil
|
|
|
|
}
|
|
|
|
if _, ok := d.GetOk("ssl_health_check"); ok {
|
|
|
|
obj["type"] = "SSL"
|
|
|
|
return obj, nil
|
|
|
|
}
|
2017-06-26 15:25:22 +00:00
|
|
|
|
2018-08-27 23:35:47 +00:00
|
|
|
return nil, fmt.Errorf("error in HealthCheck %s: No health check block specified.", d.Get("name").(string))
|
2017-06-26 15:25:22 +00:00
|
|
|
}
|