2018-03-10 01:14:32 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
//
|
2018-04-12 23:08:42 +00:00
|
|
|
// This file is automatically generated by Magic Modules and manual
|
|
|
|
// changes will be clobbered when the file is regenerated.
|
2018-03-10 01:14:32 +00:00
|
|
|
//
|
|
|
|
// Please read more about how to change this file in
|
|
|
|
// .github/CONTRIBUTING.md.
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2014-11-20 17:40:17 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2018-06-19 20:56:06 +00:00
|
|
|
"reflect"
|
2018-04-24 21:01:53 +00:00
|
|
|
"strconv"
|
2018-03-10 01:14:32 +00:00
|
|
|
"time"
|
2014-11-20 17:40:17 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
2018-03-10 01:14:32 +00:00
|
|
|
compute "google.golang.org/api/compute/v1"
|
2014-11-20 17:40:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func resourceComputeHttpHealthCheck() *schema.Resource {
|
|
|
|
return &schema.Resource{
|
|
|
|
Create: resourceComputeHttpHealthCheckCreate,
|
|
|
|
Read: resourceComputeHttpHealthCheckRead,
|
|
|
|
Update: resourceComputeHttpHealthCheckUpdate,
|
2018-03-10 01:14:32 +00:00
|
|
|
Delete: resourceComputeHttpHealthCheckDelete,
|
|
|
|
|
2016-08-04 17:53:45 +00:00
|
|
|
Importer: &schema.ResourceImporter{
|
2018-03-10 01:14:32 +00:00
|
|
|
State: resourceComputeHttpHealthCheckImport,
|
|
|
|
},
|
|
|
|
|
|
|
|
Timeouts: &schema.ResourceTimeout{
|
2018-04-12 23:08:42 +00:00
|
|
|
Create: schema.DefaultTimeout(240 * time.Second),
|
|
|
|
Update: schema.DefaultTimeout(240 * time.Second),
|
|
|
|
Delete: schema.DefaultTimeout(240 * time.Second),
|
2016-08-04 17:53:45 +00:00
|
|
|
},
|
2014-11-20 17:40:17 +00:00
|
|
|
|
|
|
|
Schema: map[string]*schema.Schema{
|
2018-03-10 01:14:32 +00:00
|
|
|
"name": {
|
2016-04-10 21:34:15 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
2018-03-10 01:14:32 +00:00
|
|
|
"check_interval_sec": {
|
2014-11-20 17:40:17 +00:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Optional: true,
|
2015-05-07 09:21:21 +00:00
|
|
|
Default: 5,
|
2014-11-20 17:40:17 +00:00
|
|
|
},
|
2018-03-10 01:14:32 +00:00
|
|
|
"description": {
|
2014-11-20 17:40:17 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
2018-03-10 01:14:32 +00:00
|
|
|
"healthy_threshold": {
|
2014-11-20 17:40:17 +00:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Optional: true,
|
2015-05-07 09:21:21 +00:00
|
|
|
Default: 2,
|
2014-11-20 17:40:17 +00:00
|
|
|
},
|
2018-03-10 01:14:32 +00:00
|
|
|
"host": {
|
2014-11-20 17:40:17 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
2018-03-10 01:14:32 +00:00
|
|
|
"port": {
|
2014-11-20 17:40:17 +00:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Optional: true,
|
2015-05-07 09:21:21 +00:00
|
|
|
Default: 80,
|
2014-11-20 17:40:17 +00:00
|
|
|
},
|
2018-03-10 01:14:32 +00:00
|
|
|
"request_path": {
|
2014-11-20 17:40:17 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
2015-05-07 09:21:21 +00:00
|
|
|
Default: "/",
|
2014-11-20 17:40:17 +00:00
|
|
|
},
|
2018-03-10 01:14:32 +00:00
|
|
|
"timeout_sec": {
|
2014-11-20 17:40:17 +00:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Optional: true,
|
2015-05-07 09:21:21 +00:00
|
|
|
Default: 5,
|
2014-11-20 17:40:17 +00:00
|
|
|
},
|
2018-03-10 01:14:32 +00:00
|
|
|
"unhealthy_threshold": {
|
2014-11-20 17:40:17 +00:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Optional: true,
|
2015-05-07 09:21:21 +00:00
|
|
|
Default: 2,
|
2014-11-20 17:40:17 +00:00
|
|
|
},
|
2018-03-10 01:14:32 +00:00
|
|
|
"creation_timestamp": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2018-04-24 23:39:20 +00:00
|
|
|
"project": {
|
2018-03-10 01:14:32 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
2018-04-24 23:39:20 +00:00
|
|
|
"self_link": {
|
2018-03-10 01:14:32 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2014-11-20 17:40:17 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceComputeHttpHealthCheckCreate(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
config := meta.(*Config)
|
|
|
|
|
2016-04-10 16:59:57 +00:00
|
|
|
project, err := getProject(d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-06-19 20:56:06 +00:00
|
|
|
obj := make(map[string]interface{})
|
2018-04-23 23:19:26 +00:00
|
|
|
checkIntervalSecProp, err := expandComputeHttpHealthCheckCheckIntervalSec(d.Get("check_interval_sec"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("check_interval_sec"); !isEmptyValue(reflect.ValueOf(checkIntervalSecProp)) && (ok || !reflect.DeepEqual(v, checkIntervalSecProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["checkIntervalSec"] = checkIntervalSecProp
|
2018-04-23 23:19:26 +00:00
|
|
|
}
|
|
|
|
descriptionProp, err := expandComputeHttpHealthCheckDescription(d.Get("description"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["description"] = descriptionProp
|
2018-04-23 23:19:26 +00:00
|
|
|
}
|
|
|
|
healthyThresholdProp, err := expandComputeHttpHealthCheckHealthyThreshold(d.Get("healthy_threshold"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("healthy_threshold"); !isEmptyValue(reflect.ValueOf(healthyThresholdProp)) && (ok || !reflect.DeepEqual(v, healthyThresholdProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["healthyThreshold"] = healthyThresholdProp
|
2018-04-23 23:19:26 +00:00
|
|
|
}
|
|
|
|
hostProp, err := expandComputeHttpHealthCheckHost(d.Get("host"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("host"); !isEmptyValue(reflect.ValueOf(hostProp)) && (ok || !reflect.DeepEqual(v, hostProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["host"] = hostProp
|
2018-04-23 23:19:26 +00:00
|
|
|
}
|
|
|
|
nameProp, err := expandComputeHttpHealthCheckName(d.Get("name"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["name"] = nameProp
|
2018-04-23 23:19:26 +00:00
|
|
|
}
|
|
|
|
portProp, err := expandComputeHttpHealthCheckPort(d.Get("port"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("port"); !isEmptyValue(reflect.ValueOf(portProp)) && (ok || !reflect.DeepEqual(v, portProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["port"] = portProp
|
2018-04-23 23:19:26 +00:00
|
|
|
}
|
|
|
|
requestPathProp, err := expandComputeHttpHealthCheckRequestPath(d.Get("request_path"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("request_path"); !isEmptyValue(reflect.ValueOf(requestPathProp)) && (ok || !reflect.DeepEqual(v, requestPathProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["requestPath"] = requestPathProp
|
2018-04-23 23:19:26 +00:00
|
|
|
}
|
|
|
|
timeoutSecProp, err := expandComputeHttpHealthCheckTimeoutSec(d.Get("timeout_sec"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("timeout_sec"); !isEmptyValue(reflect.ValueOf(timeoutSecProp)) && (ok || !reflect.DeepEqual(v, timeoutSecProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["timeoutSec"] = timeoutSecProp
|
2018-04-23 23:19:26 +00:00
|
|
|
}
|
|
|
|
unhealthyThresholdProp, err := expandComputeHttpHealthCheckUnhealthyThreshold(d.Get("unhealthy_threshold"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("unhealthy_threshold"); !isEmptyValue(reflect.ValueOf(unhealthyThresholdProp)) && (ok || !reflect.DeepEqual(v, unhealthyThresholdProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["unhealthyThreshold"] = unhealthyThresholdProp
|
2015-02-08 00:03:18 +00:00
|
|
|
}
|
2018-03-10 01:14:32 +00:00
|
|
|
|
|
|
|
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/httpHealthChecks")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2014-11-20 17:40:17 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 01:14:32 +00:00
|
|
|
log.Printf("[DEBUG] Creating new HttpHealthCheck: %#v", obj)
|
|
|
|
res, err := Post(config, url, obj)
|
2014-11-20 17:40:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error creating HttpHealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
|
2018-03-10 01:14:32 +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)
|
2014-11-20 17:40:17 +00:00
|
|
|
|
2018-03-10 01:14:32 +00:00
|
|
|
op := &compute.Operation{}
|
|
|
|
err = Convert(res, op)
|
2014-11-20 17:40:17 +00:00
|
|
|
if err != nil {
|
2015-09-24 20:30:12 +00:00
|
|
|
return err
|
2014-11-20 17:40:17 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 01:14:32 +00:00
|
|
|
waitErr := computeOperationWaitTime(
|
|
|
|
config.clientCompute, op, project, "Creating HttpHealthCheck",
|
|
|
|
int(d.Timeout(schema.TimeoutCreate).Minutes()))
|
|
|
|
|
|
|
|
if waitErr != nil {
|
|
|
|
// The resource didn't actually create
|
|
|
|
d.SetId("")
|
2018-05-01 20:48:56 +00:00
|
|
|
return fmt.Errorf("Error waiting to create HttpHealthCheck: %s", waitErr)
|
2018-03-10 01:14:32 +00:00
|
|
|
}
|
|
|
|
|
2018-05-17 23:33:30 +00:00
|
|
|
log.Printf("[DEBUG] Finished creating HttpHealthCheck %q: %#v", d.Id(), res)
|
|
|
|
|
2014-11-20 17:40:17 +00:00
|
|
|
return resourceComputeHttpHealthCheckRead(d, meta)
|
|
|
|
}
|
|
|
|
|
2018-03-10 01:14:32 +00:00
|
|
|
func resourceComputeHttpHealthCheckRead(d *schema.ResourceData, meta interface{}) error {
|
2014-11-20 17:40:17 +00:00
|
|
|
config := meta.(*Config)
|
|
|
|
|
2016-04-10 16:59:57 +00:00
|
|
|
project, err := getProject(d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-03-10 01:14:32 +00:00
|
|
|
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/httpHealthChecks/{{name}}")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2015-02-08 00:03:18 +00:00
|
|
|
}
|
2018-03-10 01:14:32 +00:00
|
|
|
|
|
|
|
res, err := Get(config, url)
|
|
|
|
if err != nil {
|
|
|
|
return handleNotFoundError(err, d, fmt.Sprintf("ComputeHttpHealthCheck %q", d.Id()))
|
2014-11-20 17:40:17 +00:00
|
|
|
}
|
2018-05-17 23:33:30 +00:00
|
|
|
|
2018-04-30 23:18:17 +00:00
|
|
|
if err := d.Set("check_interval_sec", flattenComputeHttpHealthCheckCheckIntervalSec(res["checkIntervalSec"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HttpHealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("creation_timestamp", flattenComputeHttpHealthCheckCreationTimestamp(res["creationTimestamp"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HttpHealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("description", flattenComputeHttpHealthCheckDescription(res["description"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HttpHealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("healthy_threshold", flattenComputeHttpHealthCheckHealthyThreshold(res["healthyThreshold"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HttpHealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("host", flattenComputeHttpHealthCheckHost(res["host"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HttpHealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("name", flattenComputeHttpHealthCheckName(res["name"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HttpHealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("port", flattenComputeHttpHealthCheckPort(res["port"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HttpHealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("request_path", flattenComputeHttpHealthCheckRequestPath(res["requestPath"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HttpHealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("timeout_sec", flattenComputeHttpHealthCheckTimeoutSec(res["timeoutSec"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HttpHealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("unhealthy_threshold", flattenComputeHttpHealthCheckUnhealthyThreshold(res["unhealthyThreshold"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HttpHealthCheck: %s", err)
|
|
|
|
}
|
2018-06-12 00:31:33 +00:00
|
|
|
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
|
2018-04-30 23:18:17 +00:00
|
|
|
return fmt.Errorf("Error reading HttpHealthCheck: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("project", project); err != nil {
|
|
|
|
return fmt.Errorf("Error reading HttpHealthCheck: %s", err)
|
|
|
|
}
|
2018-03-10 01:14:32 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceComputeHttpHealthCheckUpdate(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
config := meta.(*Config)
|
|
|
|
|
|
|
|
project, err := getProject(d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2014-11-20 17:40:17 +00:00
|
|
|
}
|
2018-03-10 01:14:32 +00:00
|
|
|
|
2018-06-19 20:56:06 +00:00
|
|
|
obj := make(map[string]interface{})
|
2018-04-23 23:19:26 +00:00
|
|
|
checkIntervalSecProp, err := expandComputeHttpHealthCheckCheckIntervalSec(d.Get("check_interval_sec"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-19 20:56:06 +00:00
|
|
|
} else if v, ok := d.GetOkExists("check_interval_sec"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, checkIntervalSecProp)) {
|
|
|
|
obj["checkIntervalSec"] = checkIntervalSecProp
|
2018-04-23 23:19:26 +00:00
|
|
|
}
|
|
|
|
descriptionProp, err := expandComputeHttpHealthCheckDescription(d.Get("description"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-19 20:56:06 +00:00
|
|
|
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
|
|
|
|
obj["description"] = descriptionProp
|
2018-04-23 23:19:26 +00:00
|
|
|
}
|
|
|
|
healthyThresholdProp, err := expandComputeHttpHealthCheckHealthyThreshold(d.Get("healthy_threshold"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-19 20:56:06 +00:00
|
|
|
} else if v, ok := d.GetOkExists("healthy_threshold"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, healthyThresholdProp)) {
|
|
|
|
obj["healthyThreshold"] = healthyThresholdProp
|
2018-04-23 23:19:26 +00:00
|
|
|
}
|
|
|
|
hostProp, err := expandComputeHttpHealthCheckHost(d.Get("host"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-19 20:56:06 +00:00
|
|
|
} else if v, ok := d.GetOkExists("host"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, hostProp)) {
|
|
|
|
obj["host"] = hostProp
|
2018-04-23 23:19:26 +00:00
|
|
|
}
|
|
|
|
nameProp, err := expandComputeHttpHealthCheckName(d.Get("name"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-19 20:56:06 +00:00
|
|
|
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) {
|
|
|
|
obj["name"] = nameProp
|
2018-04-23 23:19:26 +00:00
|
|
|
}
|
|
|
|
portProp, err := expandComputeHttpHealthCheckPort(d.Get("port"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-19 20:56:06 +00:00
|
|
|
} else if v, ok := d.GetOkExists("port"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, portProp)) {
|
|
|
|
obj["port"] = portProp
|
2018-04-23 23:19:26 +00:00
|
|
|
}
|
|
|
|
requestPathProp, err := expandComputeHttpHealthCheckRequestPath(d.Get("request_path"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-19 20:56:06 +00:00
|
|
|
} else if v, ok := d.GetOkExists("request_path"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, requestPathProp)) {
|
|
|
|
obj["requestPath"] = requestPathProp
|
2018-04-23 23:19:26 +00:00
|
|
|
}
|
|
|
|
timeoutSecProp, err := expandComputeHttpHealthCheckTimeoutSec(d.Get("timeout_sec"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-19 20:56:06 +00:00
|
|
|
} else if v, ok := d.GetOkExists("timeout_sec"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, timeoutSecProp)) {
|
|
|
|
obj["timeoutSec"] = timeoutSecProp
|
2018-04-23 23:19:26 +00:00
|
|
|
}
|
|
|
|
unhealthyThresholdProp, err := expandComputeHttpHealthCheckUnhealthyThreshold(d.Get("unhealthy_threshold"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-19 20:56:06 +00:00
|
|
|
} else if v, ok := d.GetOkExists("unhealthy_threshold"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, unhealthyThresholdProp)) {
|
|
|
|
obj["unhealthyThreshold"] = unhealthyThresholdProp
|
2014-11-20 17:40:17 +00:00
|
|
|
}
|
2018-03-10 01:14:32 +00:00
|
|
|
|
|
|
|
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/httpHealthChecks/{{name}}")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2014-11-20 17:40:17 +00:00
|
|
|
}
|
2018-03-10 01:14:32 +00:00
|
|
|
|
|
|
|
log.Printf("[DEBUG] Updating HttpHealthCheck %q: %#v", d.Id(), obj)
|
|
|
|
res, err := sendRequest(config, "PUT", url, obj)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error updating HttpHealthCheck %q: %s", d.Id(), err)
|
2014-11-20 17:40:17 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 01:14:32 +00:00
|
|
|
op := &compute.Operation{}
|
|
|
|
err = Convert(res, op)
|
2014-11-20 17:40:17 +00:00
|
|
|
if err != nil {
|
2018-03-10 01:14:32 +00:00
|
|
|
return err
|
2014-11-20 17:40:17 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 01:14:32 +00:00
|
|
|
err = computeOperationWaitTime(
|
|
|
|
config.clientCompute, op, project, "Updating HttpHealthCheck",
|
|
|
|
int(d.Timeout(schema.TimeoutUpdate).Minutes()))
|
2014-11-20 17:40:17 +00:00
|
|
|
|
|
|
|
if err != nil {
|
2015-09-24 20:30:12 +00:00
|
|
|
return err
|
2014-11-20 17:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return resourceComputeHttpHealthCheckRead(d, meta)
|
|
|
|
}
|
|
|
|
|
2018-03-10 01:14:32 +00:00
|
|
|
func resourceComputeHttpHealthCheckDelete(d *schema.ResourceData, meta interface{}) error {
|
2014-11-20 17:40:17 +00:00
|
|
|
config := meta.(*Config)
|
|
|
|
|
2016-04-10 16:59:57 +00:00
|
|
|
project, err := getProject(d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-03-10 01:14:32 +00:00
|
|
|
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/httpHealthChecks/{{name}}")
|
2014-11-20 17:40:17 +00:00
|
|
|
if err != nil {
|
2018-03-10 01:14:32 +00:00
|
|
|
return err
|
2014-11-20 17:40:17 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 01:14:32 +00:00
|
|
|
log.Printf("[DEBUG] Deleting HttpHealthCheck %q", d.Id())
|
|
|
|
res, err := Delete(config, url)
|
2016-04-10 16:59:57 +00:00
|
|
|
if err != nil {
|
2018-06-02 20:33:30 +00:00
|
|
|
return handleNotFoundError(err, d, "HttpHealthCheck")
|
2016-04-10 16:59:57 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 01:14:32 +00:00
|
|
|
op := &compute.Operation{}
|
|
|
|
err = Convert(res, op)
|
2014-11-20 17:40:17 +00:00
|
|
|
if err != nil {
|
2018-03-10 01:14:32 +00:00
|
|
|
return err
|
2014-11-20 17:40:17 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 01:14:32 +00:00
|
|
|
err = computeOperationWaitTime(
|
|
|
|
config.clientCompute, op, project, "Deleting HttpHealthCheck",
|
|
|
|
int(d.Timeout(schema.TimeoutDelete).Minutes()))
|
|
|
|
|
2014-11-20 17:40:17 +00:00
|
|
|
if err != nil {
|
2015-09-24 20:30:12 +00:00
|
|
|
return err
|
2014-11-20 17:40:17 +00:00
|
|
|
}
|
|
|
|
|
2018-05-17 23:33:30 +00:00
|
|
|
log.Printf("[DEBUG] Finished deleting HttpHealthCheck %q: %#v", d.Id(), res)
|
2014-11-20 17:40:17 +00:00
|
|
|
return nil
|
|
|
|
}
|
2018-03-10 01:14:32 +00:00
|
|
|
|
|
|
|
func resourceComputeHttpHealthCheckImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
|
|
|
|
config := meta.(*Config)
|
|
|
|
parseImportId([]string{"projects/(?P<project>[^/]+)/global/httpHealthChecks/(?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 flattenComputeHttpHealthCheckCheckIntervalSec(v interface{}) interface{} {
|
2018-04-24 21:01:53 +00:00
|
|
|
// Handles the string fixed64 format
|
|
|
|
if strVal, ok := v.(string); ok {
|
2018-05-03 22:35:17 +00:00
|
|
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
2018-04-24 21:01:53 +00:00
|
|
|
return intVal
|
|
|
|
} // let terraform core handle it if we can't convert the string to an int.
|
|
|
|
}
|
2018-03-10 01:14:32 +00:00
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHttpHealthCheckCreationTimestamp(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHttpHealthCheckDescription(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHttpHealthCheckHealthyThreshold(v interface{}) interface{} {
|
2018-04-24 21:01:53 +00:00
|
|
|
// Handles the string fixed64 format
|
|
|
|
if strVal, ok := v.(string); ok {
|
2018-05-03 22:35:17 +00:00
|
|
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
2018-04-24 21:01:53 +00:00
|
|
|
return intVal
|
|
|
|
} // let terraform core handle it if we can't convert the string to an int.
|
|
|
|
}
|
2018-03-10 01:14:32 +00:00
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHttpHealthCheckHost(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHttpHealthCheckName(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHttpHealthCheckPort(v interface{}) interface{} {
|
2018-04-24 21:01:53 +00:00
|
|
|
// Handles the string fixed64 format
|
|
|
|
if strVal, ok := v.(string); ok {
|
2018-05-03 22:35:17 +00:00
|
|
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
2018-04-24 21:01:53 +00:00
|
|
|
return intVal
|
|
|
|
} // let terraform core handle it if we can't convert the string to an int.
|
|
|
|
}
|
2018-03-10 01:14:32 +00:00
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHttpHealthCheckRequestPath(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHttpHealthCheckTimeoutSec(v interface{}) interface{} {
|
2018-04-24 21:01:53 +00:00
|
|
|
// Handles the string fixed64 format
|
|
|
|
if strVal, ok := v.(string); ok {
|
2018-05-03 22:35:17 +00:00
|
|
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
2018-04-24 21:01:53 +00:00
|
|
|
return intVal
|
|
|
|
} // let terraform core handle it if we can't convert the string to an int.
|
|
|
|
}
|
2018-03-10 01:14:32 +00:00
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHttpHealthCheckUnhealthyThreshold(v interface{}) interface{} {
|
2018-04-24 21:01:53 +00:00
|
|
|
// Handles the string fixed64 format
|
|
|
|
if strVal, ok := v.(string); ok {
|
2018-05-03 22:35:17 +00:00
|
|
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
2018-04-24 21:01:53 +00:00
|
|
|
return intVal
|
|
|
|
} // let terraform core handle it if we can't convert the string to an int.
|
|
|
|
}
|
2018-03-10 01:14:32 +00:00
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2018-04-23 23:19:26 +00:00
|
|
|
func expandComputeHttpHealthCheckCheckIntervalSec(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
2018-03-10 01:14:32 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 23:19:26 +00:00
|
|
|
func expandComputeHttpHealthCheckDescription(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
2018-03-10 01:14:32 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 23:19:26 +00:00
|
|
|
func expandComputeHttpHealthCheckHealthyThreshold(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
2018-03-10 01:14:32 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 23:19:26 +00:00
|
|
|
func expandComputeHttpHealthCheckHost(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
2018-03-10 01:14:32 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 23:19:26 +00:00
|
|
|
func expandComputeHttpHealthCheckName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
2018-03-10 01:14:32 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 23:19:26 +00:00
|
|
|
func expandComputeHttpHealthCheckPort(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
2018-03-10 01:14:32 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 23:19:26 +00:00
|
|
|
func expandComputeHttpHealthCheckRequestPath(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
2018-03-10 01:14:32 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 23:19:26 +00:00
|
|
|
func expandComputeHttpHealthCheckTimeoutSec(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
2018-03-10 01:14:32 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 23:19:26 +00:00
|
|
|
func expandComputeHttpHealthCheckUnhealthyThreshold(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
2018-03-10 01:14:32 +00:00
|
|
|
}
|