2018-03-10 01:14:32 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// This file is automatically generated and manual changes will be
|
|
|
|
// clobbered when the file is regenerated.
|
|
|
|
//
|
|
|
|
// 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-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{
|
|
|
|
Create: schema.DefaultTimeout(4 * time.Minute),
|
|
|
|
Update: schema.DefaultTimeout(4 * time.Minute),
|
|
|
|
Delete: schema.DefaultTimeout(4 * time.Minute),
|
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,
|
|
|
|
},
|
|
|
|
"project": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Computed: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
"self_link": &schema.Schema{
|
|
|
|
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-03-10 01:14:32 +00:00
|
|
|
obj := map[string]interface{}{
|
|
|
|
"checkIntervalSec": expandComputeHttpHealthCheckCheckIntervalSec(d.Get("check_interval_sec")),
|
|
|
|
"description": expandComputeHttpHealthCheckDescription(d.Get("description")),
|
|
|
|
"healthyThreshold": expandComputeHttpHealthCheckHealthyThreshold(d.Get("healthy_threshold")),
|
|
|
|
"host": expandComputeHttpHealthCheckHost(d.Get("host")),
|
|
|
|
"name": expandComputeHttpHealthCheckName(d.Get("name")),
|
|
|
|
"port": expandComputeHttpHealthCheckPort(d.Get("port")),
|
|
|
|
"requestPath": expandComputeHttpHealthCheckRequestPath(d.Get("request_path")),
|
|
|
|
"timeoutSec": expandComputeHttpHealthCheckTimeoutSec(d.Get("timeout_sec")),
|
|
|
|
"unhealthyThreshold": expandComputeHttpHealthCheckUnhealthyThreshold(d.Get("unhealthy_threshold")),
|
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("")
|
|
|
|
return waitErr
|
|
|
|
}
|
|
|
|
|
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-03-10 01:14:32 +00:00
|
|
|
|
|
|
|
d.Set("check_interval_sec", flattenComputeHttpHealthCheckCheckIntervalSec(res["checkIntervalSec"]))
|
|
|
|
d.Set("creation_timestamp", flattenComputeHttpHealthCheckCreationTimestamp(res["creationTimestamp"]))
|
|
|
|
d.Set("description", flattenComputeHttpHealthCheckDescription(res["description"]))
|
|
|
|
d.Set("healthy_threshold", flattenComputeHttpHealthCheckHealthyThreshold(res["healthyThreshold"]))
|
|
|
|
d.Set("host", flattenComputeHttpHealthCheckHost(res["host"]))
|
|
|
|
d.Set("name", flattenComputeHttpHealthCheckName(res["name"]))
|
|
|
|
d.Set("port", flattenComputeHttpHealthCheckPort(res["port"]))
|
|
|
|
d.Set("request_path", flattenComputeHttpHealthCheckRequestPath(res["requestPath"]))
|
|
|
|
d.Set("timeout_sec", flattenComputeHttpHealthCheckTimeoutSec(res["timeoutSec"]))
|
|
|
|
d.Set("unhealthy_threshold", flattenComputeHttpHealthCheckUnhealthyThreshold(res["unhealthyThreshold"]))
|
|
|
|
d.Set("self_link", res["selfLink"])
|
|
|
|
d.Set("project", project)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
obj := map[string]interface{}{
|
|
|
|
"checkIntervalSec": expandComputeHttpHealthCheckCheckIntervalSec(d.Get("check_interval_sec")),
|
|
|
|
"description": expandComputeHttpHealthCheckDescription(d.Get("description")),
|
|
|
|
"healthyThreshold": expandComputeHttpHealthCheckHealthyThreshold(d.Get("healthy_threshold")),
|
|
|
|
"host": expandComputeHttpHealthCheckHost(d.Get("host")),
|
|
|
|
"name": expandComputeHttpHealthCheckName(d.Get("name")),
|
|
|
|
"port": expandComputeHttpHealthCheckPort(d.Get("port")),
|
|
|
|
"requestPath": expandComputeHttpHealthCheckRequestPath(d.Get("request_path")),
|
|
|
|
"timeoutSec": expandComputeHttpHealthCheckTimeoutSec(d.Get("timeout_sec")),
|
|
|
|
"unhealthyThreshold": expandComputeHttpHealthCheckUnhealthyThreshold(d.Get("unhealthy_threshold")),
|
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-03-10 01:14:32 +00:00
|
|
|
return fmt.Errorf("Error deleting HttpHealthCheck %q: %s", d.Id(), err)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHttpHealthCheckCreationTimestamp(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHttpHealthCheckDescription(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHttpHealthCheckHealthyThreshold(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHttpHealthCheckHost(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHttpHealthCheckName(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHttpHealthCheckPort(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHttpHealthCheckRequestPath(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHttpHealthCheckTimeoutSec(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeHttpHealthCheckUnhealthyThreshold(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHttpHealthCheckCheckIntervalSec(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHttpHealthCheckDescription(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHttpHealthCheckHealthyThreshold(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHttpHealthCheckHost(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHttpHealthCheckName(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHttpHealthCheckPort(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHttpHealthCheckRequestPath(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHttpHealthCheckTimeoutSec(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeHttpHealthCheckUnhealthyThreshold(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|