terraform-provider-google/google/resource_compute_http_health_check.go

370 lines
10 KiB
Go
Raw Normal View History

// ----------------------------------------------------------------------------
//
// *** 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.
//
// ----------------------------------------------------------------------------
package google
import (
"fmt"
"log"
"time"
"github.com/hashicorp/terraform/helper/schema"
compute "google.golang.org/api/compute/v1"
)
func resourceComputeHttpHealthCheck() *schema.Resource {
return &schema.Resource{
Create: resourceComputeHttpHealthCheckCreate,
Read: resourceComputeHttpHealthCheckRead,
Update: resourceComputeHttpHealthCheckUpdate,
Delete: resourceComputeHttpHealthCheckDelete,
Importer: &schema.ResourceImporter{
State: resourceComputeHttpHealthCheckImport,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(4 * time.Minute),
Update: schema.DefaultTimeout(4 * time.Minute),
Delete: schema.DefaultTimeout(4 * time.Minute),
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"check_interval_sec": {
Type: schema.TypeInt,
Optional: true,
Default: 5,
},
"description": {
Type: schema.TypeString,
Optional: true,
},
"healthy_threshold": {
Type: schema.TypeInt,
Optional: true,
Default: 2,
},
"host": {
Type: schema.TypeString,
Optional: true,
},
"port": {
Type: schema.TypeInt,
Optional: true,
Default: 80,
},
"request_path": {
Type: schema.TypeString,
Optional: true,
Default: "/",
},
"timeout_sec": {
Type: schema.TypeInt,
Optional: true,
Default: 5,
},
"unhealthy_threshold": {
Type: schema.TypeInt,
Optional: true,
Default: 2,
},
"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,
},
},
}
}
func resourceComputeHttpHealthCheckCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
project, err := getProject(d, config)
if err != nil {
return err
}
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
}
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/httpHealthChecks")
if err != nil {
return err
}
log.Printf("[DEBUG] Creating new HttpHealthCheck: %#v", obj)
res, err := Post(config, url, obj)
if err != nil {
return fmt.Errorf("Error creating HttpHealthCheck: %s", err)
}
// Store the ID now
id, err := replaceVars(d, config, "{{name}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)
op := &compute.Operation{}
err = Convert(res, op)
if err != nil {
return err
}
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
}
return resourceComputeHttpHealthCheckRead(d, meta)
}
func resourceComputeHttpHealthCheckRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
project, err := getProject(d, config)
if err != nil {
return err
}
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
}
res, err := Get(config, url)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("ComputeHttpHealthCheck %q", d.Id()))
}
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
}
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")),
}
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/httpHealthChecks/{{name}}")
if err != nil {
return err
}
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)
}
op := &compute.Operation{}
err = Convert(res, op)
if err != nil {
return err
}
err = computeOperationWaitTime(
config.clientCompute, op, project, "Updating HttpHealthCheck",
int(d.Timeout(schema.TimeoutUpdate).Minutes()))
if err != nil {
return err
}
return resourceComputeHttpHealthCheckRead(d, meta)
}
func resourceComputeHttpHealthCheckDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
project, err := getProject(d, config)
if err != nil {
return err
}
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/httpHealthChecks/{{name}}")
if err != nil {
return err
}
log.Printf("[DEBUG] Deleting HttpHealthCheck %q", d.Id())
res, err := Delete(config, url)
if err != nil {
return fmt.Errorf("Error deleting HttpHealthCheck %q: %s", d.Id(), err)
}
op := &compute.Operation{}
err = Convert(res, op)
if err != nil {
return err
}
err = computeOperationWaitTime(
config.clientCompute, op, project, "Deleting HttpHealthCheck",
int(d.Timeout(schema.TimeoutDelete).Minutes()))
if err != nil {
return err
}
return nil
}
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
}