From 3830f3fd50a491ca8449ba4aee9ed4974b417d31 Mon Sep 17 00:00:00 2001 From: Ty Larrabee Date: Wed, 11 Dec 2019 23:35:24 +0000 Subject: [PATCH] Promote region health check to GA Signed-off-by: Modular Magician --- google/provider.go | 5 +- .../resource_compute_region_health_check.go | 1737 +++++++++++++++++ ...pute_region_health_check_generated_test.go | 478 +++++ ...source_compute_region_health_check_test.go | 341 ++++ .../compute_region_health_check.html.markdown | 622 ++++++ 5 files changed, 3181 insertions(+), 2 deletions(-) create mode 100644 google/resource_compute_region_health_check.go create mode 100644 google/resource_compute_region_health_check_generated_test.go create mode 100644 website/docs/r/compute_region_health_check.html.markdown diff --git a/google/provider.go b/google/provider.go index 9c78c276561..ec69f8fd545 100644 --- a/google/provider.go +++ b/google/provider.go @@ -460,9 +460,9 @@ func Provider() terraform.ResourceProvider { return provider } -// Generated resources: 86 +// Generated resources: 87 // Generated IAM resources: 42 -// Total generated resources: 128 +// Total generated resources: 129 func ResourceMap() map[string]*schema.Resource { resourceMap, _ := ResourceMapWithErrors() return resourceMap @@ -525,6 +525,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { "google_compute_node_template": resourceComputeNodeTemplate(), "google_compute_region_autoscaler": resourceComputeRegionAutoscaler(), "google_compute_region_disk": resourceComputeRegionDisk(), + "google_compute_region_health_check": resourceComputeRegionHealthCheck(), "google_compute_resource_policy": resourceComputeResourcePolicy(), "google_compute_route": resourceComputeRoute(), "google_compute_router": resourceComputeRouter(), diff --git a/google/resource_compute_region_health_check.go b/google/resource_compute_region_health_check.go new file mode 100644 index 00000000000..1b521dedb44 --- /dev/null +++ b/google/resource_compute_region_health_check.go @@ -0,0 +1,1737 @@ +// ---------------------------------------------------------------------------- +// +// *** 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. +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "fmt" + "log" + "reflect" + "strconv" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" +) + +func resourceComputeRegionHealthCheck() *schema.Resource { + return &schema.Resource{ + Create: resourceComputeRegionHealthCheckCreate, + Read: resourceComputeRegionHealthCheckRead, + Update: resourceComputeRegionHealthCheckUpdate, + Delete: resourceComputeRegionHealthCheckDelete, + + Importer: &schema.ResourceImporter{ + State: resourceComputeRegionHealthCheckImport, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(4 * time.Minute), + Update: schema.DefaultTimeout(4 * time.Minute), + Delete: schema.DefaultTimeout(4 * time.Minute), + }, + + CustomizeDiff: healthCheckCustomizeDiff, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `Name of the resource. Provided by the client when the resource is +created. The name must be 1-63 characters long, and comply with +RFC1035. Specifically, the name must be 1-63 characters long and +match the regular expression '[a-z]([-a-z0-9]*[a-z0-9])?' which means +the first character must be a lowercase letter, and all following +characters must be a dash, lowercase letter, or digit, except the +last character, which cannot be a dash.`, + }, + "check_interval_sec": { + Type: schema.TypeInt, + Optional: true, + Description: `How often (in seconds) to send a health check. The default value is 5 +seconds.`, + Default: 5, + }, + "description": { + Type: schema.TypeString, + Optional: true, + Description: `An optional description of this resource. Provide this property when +you create the resource.`, + }, + "healthy_threshold": { + Type: schema.TypeInt, + Optional: true, + Description: `A so-far unhealthy instance will be marked healthy after this many +consecutive successes. The default value is 2.`, + Default: 2, + }, + "http2_health_check": { + Type: schema.TypeList, + Optional: true, + DiffSuppressFunc: portDiffSuppress, + Description: `A nested object resource`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "host": { + Type: schema.TypeString, + Optional: true, + Description: `The value of the host header in the HTTP2 health check request. +If left empty (default value), the public IP on behalf of which this health +check is performed will be used.`, + AtLeastOneOf: []string{"http2_health_check.0.host", "http2_health_check.0.request_path", "http2_health_check.0.response", "http2_health_check.0.port", "http2_health_check.0.port_name", "http2_health_check.0.proxy_header", "http2_health_check.0.port_specification"}, + }, + "port": { + Type: schema.TypeInt, + Optional: true, + Description: `The TCP port number for the HTTP2 health check request. +The default value is 443.`, + AtLeastOneOf: []string{"http2_health_check.0.host", "http2_health_check.0.request_path", "http2_health_check.0.response", "http2_health_check.0.port", "http2_health_check.0.port_name", "http2_health_check.0.proxy_header", "http2_health_check.0.port_specification"}, + }, + "port_name": { + Type: schema.TypeString, + Optional: true, + Description: `Port name as defined in InstanceGroup#NamedPort#name. If both port and +port_name are defined, port takes precedence.`, + AtLeastOneOf: []string{"http2_health_check.0.host", "http2_health_check.0.request_path", "http2_health_check.0.response", "http2_health_check.0.port", "http2_health_check.0.port_name", "http2_health_check.0.proxy_header", "http2_health_check.0.port_specification"}, + }, + "port_specification": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"USE_FIXED_PORT", "USE_NAMED_PORT", "USE_SERVING_PORT", ""}, false), + Description: `Specifies how port is selected for health checking, can be one of the +following values: + + * 'USE_FIXED_PORT': The port number in 'port' is used for health checking. + + * 'USE_NAMED_PORT': The 'portName' is used for health checking. + + * 'USE_SERVING_PORT': For NetworkEndpointGroup, the port specified for each + network endpoint is used for health checking. For other backends, the + port or named port specified in the Backend Service is used for health + checking. + +If not specified, HTTP2 health check follows behavior specified in 'port' and +'portName' fields.`, + AtLeastOneOf: []string{"http2_health_check.0.host", "http2_health_check.0.request_path", "http2_health_check.0.response", "http2_health_check.0.port", "http2_health_check.0.port_name", "http2_health_check.0.proxy_header", "http2_health_check.0.port_specification"}, + }, + "proxy_header": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"NONE", "PROXY_V1", ""}, false), + Description: `Specifies the type of proxy header to append before sending data to the +backend, either NONE or PROXY_V1. The default is NONE.`, + Default: "NONE", + AtLeastOneOf: []string{"http2_health_check.0.host", "http2_health_check.0.request_path", "http2_health_check.0.response", "http2_health_check.0.port", "http2_health_check.0.port_name", "http2_health_check.0.proxy_header", "http2_health_check.0.port_specification"}, + }, + "request_path": { + Type: schema.TypeString, + Optional: true, + Description: `The request path of the HTTP2 health check request. +The default value is /.`, + Default: "/", + AtLeastOneOf: []string{"http2_health_check.0.host", "http2_health_check.0.request_path", "http2_health_check.0.response", "http2_health_check.0.port", "http2_health_check.0.port_name", "http2_health_check.0.proxy_header", "http2_health_check.0.port_specification"}, + }, + "response": { + Type: schema.TypeString, + Optional: true, + Description: `The bytes to match against the beginning of the response data. If left empty +(the default value), any response will indicate health. The response data +can only be ASCII.`, + AtLeastOneOf: []string{"http2_health_check.0.host", "http2_health_check.0.request_path", "http2_health_check.0.response", "http2_health_check.0.port", "http2_health_check.0.port_name", "http2_health_check.0.proxy_header", "http2_health_check.0.port_specification"}, + }, + }, + }, + ExactlyOneOf: []string{"http_health_check", "https_health_check", "http2_health_check", "tcp_health_check", "ssl_health_check"}, + }, + "http_health_check": { + Type: schema.TypeList, + Optional: true, + DiffSuppressFunc: portDiffSuppress, + Description: `A nested object resource`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "host": { + Type: schema.TypeString, + Optional: true, + Description: `The value of the host header in the HTTP health check request. +If left empty (default value), the public IP on behalf of which this health +check is performed will be used.`, + AtLeastOneOf: []string{"http_health_check.0.host", "http_health_check.0.request_path", "http_health_check.0.response", "http_health_check.0.port", "http_health_check.0.port_name", "http_health_check.0.proxy_header", "http_health_check.0.port_specification"}, + }, + "port": { + Type: schema.TypeInt, + Optional: true, + Description: `The TCP port number for the HTTP health check request. +The default value is 80.`, + AtLeastOneOf: []string{"http_health_check.0.host", "http_health_check.0.request_path", "http_health_check.0.response", "http_health_check.0.port", "http_health_check.0.port_name", "http_health_check.0.proxy_header", "http_health_check.0.port_specification"}, + }, + "port_name": { + Type: schema.TypeString, + Optional: true, + Description: `Port name as defined in InstanceGroup#NamedPort#name. If both port and +port_name are defined, port takes precedence.`, + AtLeastOneOf: []string{"http_health_check.0.host", "http_health_check.0.request_path", "http_health_check.0.response", "http_health_check.0.port", "http_health_check.0.port_name", "http_health_check.0.proxy_header", "http_health_check.0.port_specification"}, + }, + "port_specification": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"USE_FIXED_PORT", "USE_NAMED_PORT", "USE_SERVING_PORT", ""}, false), + Description: `Specifies how port is selected for health checking, can be one of the +following values: + + * 'USE_FIXED_PORT': The port number in 'port' is used for health checking. + + * 'USE_NAMED_PORT': The 'portName' is used for health checking. + + * 'USE_SERVING_PORT': For NetworkEndpointGroup, the port specified for each + network endpoint is used for health checking. For other backends, the + port or named port specified in the Backend Service is used for health + checking. + +If not specified, HTTP health check follows behavior specified in 'port' and +'portName' fields.`, + AtLeastOneOf: []string{"http_health_check.0.host", "http_health_check.0.request_path", "http_health_check.0.response", "http_health_check.0.port", "http_health_check.0.port_name", "http_health_check.0.proxy_header", "http_health_check.0.port_specification"}, + }, + "proxy_header": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"NONE", "PROXY_V1", ""}, false), + Description: `Specifies the type of proxy header to append before sending data to the +backend, either NONE or PROXY_V1. The default is NONE.`, + Default: "NONE", + AtLeastOneOf: []string{"http_health_check.0.host", "http_health_check.0.request_path", "http_health_check.0.response", "http_health_check.0.port", "http_health_check.0.port_name", "http_health_check.0.proxy_header", "http_health_check.0.port_specification"}, + }, + "request_path": { + Type: schema.TypeString, + Optional: true, + Description: `The request path of the HTTP health check request. +The default value is /.`, + Default: "/", + AtLeastOneOf: []string{"http_health_check.0.host", "http_health_check.0.request_path", "http_health_check.0.response", "http_health_check.0.port", "http_health_check.0.port_name", "http_health_check.0.proxy_header", "http_health_check.0.port_specification"}, + }, + "response": { + Type: schema.TypeString, + Optional: true, + Description: `The bytes to match against the beginning of the response data. If left empty +(the default value), any response will indicate health. The response data +can only be ASCII.`, + AtLeastOneOf: []string{"http_health_check.0.host", "http_health_check.0.request_path", "http_health_check.0.response", "http_health_check.0.port", "http_health_check.0.port_name", "http_health_check.0.proxy_header", "http_health_check.0.port_specification"}, + }, + }, + }, + ExactlyOneOf: []string{"http_health_check", "https_health_check", "http2_health_check", "tcp_health_check", "ssl_health_check"}, + }, + "https_health_check": { + Type: schema.TypeList, + Optional: true, + DiffSuppressFunc: portDiffSuppress, + Description: `A nested object resource`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "host": { + Type: schema.TypeString, + Optional: true, + Description: `The value of the host header in the HTTPS health check request. +If left empty (default value), the public IP on behalf of which this health +check is performed will be used.`, + AtLeastOneOf: []string{"https_health_check.0.host", "https_health_check.0.request_path", "https_health_check.0.response", "https_health_check.0.port", "https_health_check.0.port_name", "https_health_check.0.proxy_header", "https_health_check.0.port_specification"}, + }, + "port": { + Type: schema.TypeInt, + Optional: true, + Description: `The TCP port number for the HTTPS health check request. +The default value is 443.`, + AtLeastOneOf: []string{"https_health_check.0.host", "https_health_check.0.request_path", "https_health_check.0.response", "https_health_check.0.port", "https_health_check.0.port_name", "https_health_check.0.proxy_header", "https_health_check.0.port_specification"}, + }, + "port_name": { + Type: schema.TypeString, + Optional: true, + Description: `Port name as defined in InstanceGroup#NamedPort#name. If both port and +port_name are defined, port takes precedence.`, + AtLeastOneOf: []string{"https_health_check.0.host", "https_health_check.0.request_path", "https_health_check.0.response", "https_health_check.0.port", "https_health_check.0.port_name", "https_health_check.0.proxy_header", "https_health_check.0.port_specification"}, + }, + "port_specification": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"USE_FIXED_PORT", "USE_NAMED_PORT", "USE_SERVING_PORT", ""}, false), + Description: `Specifies how port is selected for health checking, can be one of the +following values: + + * 'USE_FIXED_PORT': The port number in 'port' is used for health checking. + + * 'USE_NAMED_PORT': The 'portName' is used for health checking. + + * 'USE_SERVING_PORT': For NetworkEndpointGroup, the port specified for each + network endpoint is used for health checking. For other backends, the + port or named port specified in the Backend Service is used for health + checking. + +If not specified, HTTPS health check follows behavior specified in 'port' and +'portName' fields.`, + AtLeastOneOf: []string{"https_health_check.0.host", "https_health_check.0.request_path", "https_health_check.0.response", "https_health_check.0.port", "https_health_check.0.port_name", "https_health_check.0.proxy_header", "https_health_check.0.port_specification"}, + }, + "proxy_header": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"NONE", "PROXY_V1", ""}, false), + Description: `Specifies the type of proxy header to append before sending data to the +backend, either NONE or PROXY_V1. The default is NONE.`, + Default: "NONE", + AtLeastOneOf: []string{"https_health_check.0.host", "https_health_check.0.request_path", "https_health_check.0.response", "https_health_check.0.port", "https_health_check.0.port_name", "https_health_check.0.proxy_header", "https_health_check.0.port_specification"}, + }, + "request_path": { + Type: schema.TypeString, + Optional: true, + Description: `The request path of the HTTPS health check request. +The default value is /.`, + Default: "/", + AtLeastOneOf: []string{"https_health_check.0.host", "https_health_check.0.request_path", "https_health_check.0.response", "https_health_check.0.port", "https_health_check.0.port_name", "https_health_check.0.proxy_header", "https_health_check.0.port_specification"}, + }, + "response": { + Type: schema.TypeString, + Optional: true, + Description: `The bytes to match against the beginning of the response data. If left empty +(the default value), any response will indicate health. The response data +can only be ASCII.`, + AtLeastOneOf: []string{"https_health_check.0.host", "https_health_check.0.request_path", "https_health_check.0.response", "https_health_check.0.port", "https_health_check.0.port_name", "https_health_check.0.proxy_header", "https_health_check.0.port_specification"}, + }, + }, + }, + ExactlyOneOf: []string{"http_health_check", "https_health_check", "http2_health_check", "tcp_health_check", "ssl_health_check"}, + }, + "region": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + Description: `The Region in which the created health check should reside. +If it is not provided, the provider region is used.`, + }, + "ssl_health_check": { + Type: schema.TypeList, + Optional: true, + DiffSuppressFunc: portDiffSuppress, + Description: `A nested object resource`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "port": { + Type: schema.TypeInt, + Optional: true, + Description: `The TCP port number for the SSL health check request. +The default value is 443.`, + AtLeastOneOf: []string{"ssl_health_check.0.request", "ssl_health_check.0.response", "ssl_health_check.0.port", "ssl_health_check.0.port_name", "ssl_health_check.0.proxy_header", "ssl_health_check.0.port_specification"}, + }, + "port_name": { + Type: schema.TypeString, + Optional: true, + Description: `Port name as defined in InstanceGroup#NamedPort#name. If both port and +port_name are defined, port takes precedence.`, + AtLeastOneOf: []string{"ssl_health_check.0.request", "ssl_health_check.0.response", "ssl_health_check.0.port", "ssl_health_check.0.port_name", "ssl_health_check.0.proxy_header", "ssl_health_check.0.port_specification"}, + }, + "port_specification": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"USE_FIXED_PORT", "USE_NAMED_PORT", "USE_SERVING_PORT", ""}, false), + Description: `Specifies how port is selected for health checking, can be one of the +following values: + + * 'USE_FIXED_PORT': The port number in 'port' is used for health checking. + + * 'USE_NAMED_PORT': The 'portName' is used for health checking. + + * 'USE_SERVING_PORT': For NetworkEndpointGroup, the port specified for each + network endpoint is used for health checking. For other backends, the + port or named port specified in the Backend Service is used for health + checking. + +If not specified, SSL health check follows behavior specified in 'port' and +'portName' fields.`, + AtLeastOneOf: []string{"ssl_health_check.0.request", "ssl_health_check.0.response", "ssl_health_check.0.port", "ssl_health_check.0.port_name", "ssl_health_check.0.proxy_header", "ssl_health_check.0.port_specification"}, + }, + "proxy_header": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"NONE", "PROXY_V1", ""}, false), + Description: `Specifies the type of proxy header to append before sending data to the +backend, either NONE or PROXY_V1. The default is NONE.`, + Default: "NONE", + AtLeastOneOf: []string{"ssl_health_check.0.request", "ssl_health_check.0.response", "ssl_health_check.0.port", "ssl_health_check.0.port_name", "ssl_health_check.0.proxy_header", "ssl_health_check.0.port_specification"}, + }, + "request": { + Type: schema.TypeString, + Optional: true, + Description: `The application data to send once the SSL connection has been +established (default value is empty). If both request and response are +empty, the connection establishment alone will indicate health. The request +data can only be ASCII.`, + AtLeastOneOf: []string{"ssl_health_check.0.request", "ssl_health_check.0.response", "ssl_health_check.0.port", "ssl_health_check.0.port_name", "ssl_health_check.0.proxy_header", "ssl_health_check.0.port_specification"}, + }, + "response": { + Type: schema.TypeString, + Optional: true, + Description: `The bytes to match against the beginning of the response data. If left empty +(the default value), any response will indicate health. The response data +can only be ASCII.`, + AtLeastOneOf: []string{"ssl_health_check.0.request", "ssl_health_check.0.response", "ssl_health_check.0.port", "ssl_health_check.0.port_name", "ssl_health_check.0.proxy_header", "ssl_health_check.0.port_specification"}, + }, + }, + }, + ExactlyOneOf: []string{"http_health_check", "https_health_check", "http2_health_check", "tcp_health_check", "ssl_health_check"}, + }, + "tcp_health_check": { + Type: schema.TypeList, + Optional: true, + DiffSuppressFunc: portDiffSuppress, + Description: `A nested object resource`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "port": { + Type: schema.TypeInt, + Optional: true, + Description: `The TCP port number for the TCP health check request. +The default value is 80.`, + AtLeastOneOf: []string{"tcp_health_check.0.request", "tcp_health_check.0.response", "tcp_health_check.0.port", "tcp_health_check.0.port_name", "tcp_health_check.0.proxy_header", "tcp_health_check.0.port_specification"}, + }, + "port_name": { + Type: schema.TypeString, + Optional: true, + Description: `Port name as defined in InstanceGroup#NamedPort#name. If both port and +port_name are defined, port takes precedence.`, + AtLeastOneOf: []string{"tcp_health_check.0.request", "tcp_health_check.0.response", "tcp_health_check.0.port", "tcp_health_check.0.port_name", "tcp_health_check.0.proxy_header", "tcp_health_check.0.port_specification"}, + }, + "port_specification": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"USE_FIXED_PORT", "USE_NAMED_PORT", "USE_SERVING_PORT", ""}, false), + Description: `Specifies how port is selected for health checking, can be one of the +following values: + + * 'USE_FIXED_PORT': The port number in 'port' is used for health checking. + + * 'USE_NAMED_PORT': The 'portName' is used for health checking. + + * 'USE_SERVING_PORT': For NetworkEndpointGroup, the port specified for each + network endpoint is used for health checking. For other backends, the + port or named port specified in the Backend Service is used for health + checking. + +If not specified, TCP health check follows behavior specified in 'port' and +'portName' fields.`, + AtLeastOneOf: []string{"tcp_health_check.0.request", "tcp_health_check.0.response", "tcp_health_check.0.port", "tcp_health_check.0.port_name", "tcp_health_check.0.proxy_header", "tcp_health_check.0.port_specification"}, + }, + "proxy_header": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"NONE", "PROXY_V1", ""}, false), + Description: `Specifies the type of proxy header to append before sending data to the +backend, either NONE or PROXY_V1. The default is NONE.`, + Default: "NONE", + AtLeastOneOf: []string{"tcp_health_check.0.request", "tcp_health_check.0.response", "tcp_health_check.0.port", "tcp_health_check.0.port_name", "tcp_health_check.0.proxy_header", "tcp_health_check.0.port_specification"}, + }, + "request": { + Type: schema.TypeString, + Optional: true, + Description: `The application data to send once the TCP connection has been +established (default value is empty). If both request and response are +empty, the connection establishment alone will indicate health. The request +data can only be ASCII.`, + AtLeastOneOf: []string{"tcp_health_check.0.request", "tcp_health_check.0.response", "tcp_health_check.0.port", "tcp_health_check.0.port_name", "tcp_health_check.0.proxy_header", "tcp_health_check.0.port_specification"}, + }, + "response": { + Type: schema.TypeString, + Optional: true, + Description: `The bytes to match against the beginning of the response data. If left empty +(the default value), any response will indicate health. The response data +can only be ASCII.`, + AtLeastOneOf: []string{"tcp_health_check.0.request", "tcp_health_check.0.response", "tcp_health_check.0.port", "tcp_health_check.0.port_name", "tcp_health_check.0.proxy_header", "tcp_health_check.0.port_specification"}, + }, + }, + }, + ExactlyOneOf: []string{"http_health_check", "https_health_check", "http2_health_check", "tcp_health_check", "ssl_health_check"}, + }, + "timeout_sec": { + Type: schema.TypeInt, + Optional: true, + Description: `How long (in seconds) to wait before claiming failure. +The default value is 5 seconds. It is invalid for timeoutSec to have +greater value than checkIntervalSec.`, + Default: 5, + }, + "unhealthy_threshold": { + Type: schema.TypeInt, + Optional: true, + Description: `A so-far healthy instance will be marked unhealthy after this many +consecutive failures. The default value is 2.`, + Default: 2, + }, + "creation_timestamp": { + Type: schema.TypeString, + Computed: true, + Description: `Creation timestamp in RFC3339 text format.`, + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: `The type of the health check. One of HTTP, HTTP2, HTTPS, TCP, or SSL.`, + }, + "project": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "self_link": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func resourceComputeRegionHealthCheckCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + obj := make(map[string]interface{}) + checkIntervalSecProp, err := expandComputeRegionHealthCheckCheckIntervalSec(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 := expandComputeRegionHealthCheckDescription(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 := expandComputeRegionHealthCheckHealthyThreshold(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 := expandComputeRegionHealthCheckName(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 + } + unhealthyThresholdProp, err := expandComputeRegionHealthCheckUnhealthyThreshold(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 + } + timeoutSecProp, err := expandComputeRegionHealthCheckTimeoutSec(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 + } + httpHealthCheckProp, err := expandComputeRegionHealthCheckHttpHealthCheck(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 := expandComputeRegionHealthCheckHttpsHealthCheck(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 := expandComputeRegionHealthCheckTcpHealthCheck(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 := expandComputeRegionHealthCheckSslHealthCheck(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 + } + http2HealthCheckProp, err := expandComputeRegionHealthCheckHttp2HealthCheck(d.Get("http2_health_check"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("http2_health_check"); !isEmptyValue(reflect.ValueOf(http2HealthCheckProp)) && (ok || !reflect.DeepEqual(v, http2HealthCheckProp)) { + obj["http2HealthCheck"] = http2HealthCheckProp + } + regionProp, err := expandComputeRegionHealthCheckRegion(d.Get("region"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("region"); !isEmptyValue(reflect.ValueOf(regionProp)) && (ok || !reflect.DeepEqual(v, regionProp)) { + obj["region"] = regionProp + } + + obj, err = resourceComputeRegionHealthCheckEncoder(d, meta, obj) + if err != nil { + return err + } + + url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/healthChecks") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new RegionHealthCheck: %#v", obj) + project, err := getProject(d, config) + if err != nil { + return err + } + res, err := sendRequestWithTimeout(config, "POST", project, url, obj, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return fmt.Errorf("Error creating RegionHealthCheck: %s", err) + } + + // Store the ID now + id, err := replaceVars(d, config, "projects/{{project}}/regions/{{region}}/healthChecks/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + err = computeOperationWaitTime( + config, res, project, "Creating RegionHealthCheck", + int(d.Timeout(schema.TimeoutCreate).Minutes())) + + if err != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error waiting to create RegionHealthCheck: %s", err) + } + + log.Printf("[DEBUG] Finished creating RegionHealthCheck %q: %#v", d.Id(), res) + + return resourceComputeRegionHealthCheckRead(d, meta) +} + +func resourceComputeRegionHealthCheckRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/healthChecks/{{name}}") + if err != nil { + return err + } + + project, err := getProject(d, config) + if err != nil { + return err + } + res, err := sendRequest(config, "GET", project, url, nil) + if err != nil { + return handleNotFoundError(err, d, fmt.Sprintf("ComputeRegionHealthCheck %q", d.Id())) + } + + if err := d.Set("project", project); err != nil { + return fmt.Errorf("Error reading RegionHealthCheck: %s", err) + } + + if err := d.Set("check_interval_sec", flattenComputeRegionHealthCheckCheckIntervalSec(res["checkIntervalSec"], d)); err != nil { + return fmt.Errorf("Error reading RegionHealthCheck: %s", err) + } + if err := d.Set("creation_timestamp", flattenComputeRegionHealthCheckCreationTimestamp(res["creationTimestamp"], d)); err != nil { + return fmt.Errorf("Error reading RegionHealthCheck: %s", err) + } + if err := d.Set("description", flattenComputeRegionHealthCheckDescription(res["description"], d)); err != nil { + return fmt.Errorf("Error reading RegionHealthCheck: %s", err) + } + if err := d.Set("healthy_threshold", flattenComputeRegionHealthCheckHealthyThreshold(res["healthyThreshold"], d)); err != nil { + return fmt.Errorf("Error reading RegionHealthCheck: %s", err) + } + if err := d.Set("name", flattenComputeRegionHealthCheckName(res["name"], d)); err != nil { + return fmt.Errorf("Error reading RegionHealthCheck: %s", err) + } + if err := d.Set("unhealthy_threshold", flattenComputeRegionHealthCheckUnhealthyThreshold(res["unhealthyThreshold"], d)); err != nil { + return fmt.Errorf("Error reading RegionHealthCheck: %s", err) + } + if err := d.Set("timeout_sec", flattenComputeRegionHealthCheckTimeoutSec(res["timeoutSec"], d)); err != nil { + return fmt.Errorf("Error reading RegionHealthCheck: %s", err) + } + if err := d.Set("type", flattenComputeRegionHealthCheckType(res["type"], d)); err != nil { + return fmt.Errorf("Error reading RegionHealthCheck: %s", err) + } + if err := d.Set("http_health_check", flattenComputeRegionHealthCheckHttpHealthCheck(res["httpHealthCheck"], d)); err != nil { + return fmt.Errorf("Error reading RegionHealthCheck: %s", err) + } + if err := d.Set("https_health_check", flattenComputeRegionHealthCheckHttpsHealthCheck(res["httpsHealthCheck"], d)); err != nil { + return fmt.Errorf("Error reading RegionHealthCheck: %s", err) + } + if err := d.Set("tcp_health_check", flattenComputeRegionHealthCheckTcpHealthCheck(res["tcpHealthCheck"], d)); err != nil { + return fmt.Errorf("Error reading RegionHealthCheck: %s", err) + } + if err := d.Set("ssl_health_check", flattenComputeRegionHealthCheckSslHealthCheck(res["sslHealthCheck"], d)); err != nil { + return fmt.Errorf("Error reading RegionHealthCheck: %s", err) + } + if err := d.Set("http2_health_check", flattenComputeRegionHealthCheckHttp2HealthCheck(res["http2HealthCheck"], d)); err != nil { + return fmt.Errorf("Error reading RegionHealthCheck: %s", err) + } + if err := d.Set("region", flattenComputeRegionHealthCheckRegion(res["region"], d)); err != nil { + return fmt.Errorf("Error reading RegionHealthCheck: %s", err) + } + if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil { + return fmt.Errorf("Error reading RegionHealthCheck: %s", err) + } + + return nil +} + +func resourceComputeRegionHealthCheckUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + project, err := getProject(d, config) + if err != nil { + return err + } + + obj := make(map[string]interface{}) + checkIntervalSecProp, err := expandComputeRegionHealthCheckCheckIntervalSec(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 := expandComputeRegionHealthCheckDescription(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 := expandComputeRegionHealthCheckHealthyThreshold(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 := expandComputeRegionHealthCheckName(d.Get("name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) { + obj["name"] = nameProp + } + unhealthyThresholdProp, err := expandComputeRegionHealthCheckUnhealthyThreshold(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 + } + timeoutSecProp, err := expandComputeRegionHealthCheckTimeoutSec(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 + } + httpHealthCheckProp, err := expandComputeRegionHealthCheckHttpHealthCheck(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 := expandComputeRegionHealthCheckHttpsHealthCheck(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 := expandComputeRegionHealthCheckTcpHealthCheck(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 := expandComputeRegionHealthCheckSslHealthCheck(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 + } + http2HealthCheckProp, err := expandComputeRegionHealthCheckHttp2HealthCheck(d.Get("http2_health_check"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("http2_health_check"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, http2HealthCheckProp)) { + obj["http2HealthCheck"] = http2HealthCheckProp + } + regionProp, err := expandComputeRegionHealthCheckRegion(d.Get("region"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("region"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, regionProp)) { + obj["region"] = regionProp + } + + obj, err = resourceComputeRegionHealthCheckEncoder(d, meta, obj) + if err != nil { + return err + } + + url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/healthChecks/{{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Updating RegionHealthCheck %q: %#v", d.Id(), obj) + res, err := sendRequestWithTimeout(config, "PUT", project, url, obj, d.Timeout(schema.TimeoutUpdate)) + + if err != nil { + return fmt.Errorf("Error updating RegionHealthCheck %q: %s", d.Id(), err) + } + + err = computeOperationWaitTime( + config, res, project, "Updating RegionHealthCheck", + int(d.Timeout(schema.TimeoutUpdate).Minutes())) + + if err != nil { + return err + } + + return resourceComputeRegionHealthCheckRead(d, meta) +} + +func resourceComputeRegionHealthCheckDelete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + project, err := getProject(d, config) + if err != nil { + return err + } + + url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/healthChecks/{{name}}") + if err != nil { + return err + } + + var obj map[string]interface{} + log.Printf("[DEBUG] Deleting RegionHealthCheck %q", d.Id()) + + res, err := sendRequestWithTimeout(config, "DELETE", project, url, obj, d.Timeout(schema.TimeoutDelete)) + if err != nil { + return handleNotFoundError(err, d, "RegionHealthCheck") + } + + err = computeOperationWaitTime( + config, res, project, "Deleting RegionHealthCheck", + int(d.Timeout(schema.TimeoutDelete).Minutes())) + + if err != nil { + return err + } + + log.Printf("[DEBUG] Finished deleting RegionHealthCheck %q: %#v", d.Id(), res) + return nil +} + +func resourceComputeRegionHealthCheckImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*Config) + if err := parseImportId([]string{ + "projects/(?P[^/]+)/regions/(?P[^/]+)/healthChecks/(?P[^/]+)", + "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", + "(?P[^/]+)/(?P[^/]+)", + "(?P[^/]+)", + }, d, config); err != nil { + return nil, err + } + + // Replace import id for the resource id + id, err := replaceVars(d, config, "projects/{{project}}/regions/{{region}}/healthChecks/{{name}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + return []*schema.ResourceData{d}, nil +} + +func flattenComputeRegionHealthCheckCheckIntervalSec(v interface{}, d *schema.ResourceData) 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 flattenComputeRegionHealthCheckCreationTimestamp(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckDescription(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHealthyThreshold(v interface{}, d *schema.ResourceData) 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 flattenComputeRegionHealthCheckName(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckUnhealthyThreshold(v interface{}, d *schema.ResourceData) 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 flattenComputeRegionHealthCheckTimeoutSec(v interface{}, d *schema.ResourceData) 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 flattenComputeRegionHealthCheckType(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHttpHealthCheck(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["host"] = + flattenComputeRegionHealthCheckHttpHealthCheckHost(original["host"], d) + transformed["request_path"] = + flattenComputeRegionHealthCheckHttpHealthCheckRequestPath(original["requestPath"], d) + transformed["response"] = + flattenComputeRegionHealthCheckHttpHealthCheckResponse(original["response"], d) + transformed["port"] = + flattenComputeRegionHealthCheckHttpHealthCheckPort(original["port"], d) + transformed["port_name"] = + flattenComputeRegionHealthCheckHttpHealthCheckPortName(original["portName"], d) + transformed["proxy_header"] = + flattenComputeRegionHealthCheckHttpHealthCheckProxyHeader(original["proxyHeader"], d) + transformed["port_specification"] = + flattenComputeRegionHealthCheckHttpHealthCheckPortSpecification(original["portSpecification"], d) + return []interface{}{transformed} +} +func flattenComputeRegionHealthCheckHttpHealthCheckHost(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHttpHealthCheckRequestPath(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHttpHealthCheckResponse(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHttpHealthCheckPort(v interface{}, d *schema.ResourceData) 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 flattenComputeRegionHealthCheckHttpHealthCheckPortName(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHttpHealthCheckProxyHeader(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHttpHealthCheckPortSpecification(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHttpsHealthCheck(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["host"] = + flattenComputeRegionHealthCheckHttpsHealthCheckHost(original["host"], d) + transformed["request_path"] = + flattenComputeRegionHealthCheckHttpsHealthCheckRequestPath(original["requestPath"], d) + transformed["response"] = + flattenComputeRegionHealthCheckHttpsHealthCheckResponse(original["response"], d) + transformed["port"] = + flattenComputeRegionHealthCheckHttpsHealthCheckPort(original["port"], d) + transformed["port_name"] = + flattenComputeRegionHealthCheckHttpsHealthCheckPortName(original["portName"], d) + transformed["proxy_header"] = + flattenComputeRegionHealthCheckHttpsHealthCheckProxyHeader(original["proxyHeader"], d) + transformed["port_specification"] = + flattenComputeRegionHealthCheckHttpsHealthCheckPortSpecification(original["portSpecification"], d) + return []interface{}{transformed} +} +func flattenComputeRegionHealthCheckHttpsHealthCheckHost(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHttpsHealthCheckRequestPath(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHttpsHealthCheckResponse(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHttpsHealthCheckPort(v interface{}, d *schema.ResourceData) 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 flattenComputeRegionHealthCheckHttpsHealthCheckPortName(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHttpsHealthCheckProxyHeader(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHttpsHealthCheckPortSpecification(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckTcpHealthCheck(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["request"] = + flattenComputeRegionHealthCheckTcpHealthCheckRequest(original["request"], d) + transformed["response"] = + flattenComputeRegionHealthCheckTcpHealthCheckResponse(original["response"], d) + transformed["port"] = + flattenComputeRegionHealthCheckTcpHealthCheckPort(original["port"], d) + transformed["port_name"] = + flattenComputeRegionHealthCheckTcpHealthCheckPortName(original["portName"], d) + transformed["proxy_header"] = + flattenComputeRegionHealthCheckTcpHealthCheckProxyHeader(original["proxyHeader"], d) + transformed["port_specification"] = + flattenComputeRegionHealthCheckTcpHealthCheckPortSpecification(original["portSpecification"], d) + return []interface{}{transformed} +} +func flattenComputeRegionHealthCheckTcpHealthCheckRequest(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckTcpHealthCheckResponse(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckTcpHealthCheckPort(v interface{}, d *schema.ResourceData) 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 flattenComputeRegionHealthCheckTcpHealthCheckPortName(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckTcpHealthCheckProxyHeader(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckTcpHealthCheckPortSpecification(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckSslHealthCheck(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["request"] = + flattenComputeRegionHealthCheckSslHealthCheckRequest(original["request"], d) + transformed["response"] = + flattenComputeRegionHealthCheckSslHealthCheckResponse(original["response"], d) + transformed["port"] = + flattenComputeRegionHealthCheckSslHealthCheckPort(original["port"], d) + transformed["port_name"] = + flattenComputeRegionHealthCheckSslHealthCheckPortName(original["portName"], d) + transformed["proxy_header"] = + flattenComputeRegionHealthCheckSslHealthCheckProxyHeader(original["proxyHeader"], d) + transformed["port_specification"] = + flattenComputeRegionHealthCheckSslHealthCheckPortSpecification(original["portSpecification"], d) + return []interface{}{transformed} +} +func flattenComputeRegionHealthCheckSslHealthCheckRequest(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckSslHealthCheckResponse(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckSslHealthCheckPort(v interface{}, d *schema.ResourceData) 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 flattenComputeRegionHealthCheckSslHealthCheckPortName(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckSslHealthCheckProxyHeader(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckSslHealthCheckPortSpecification(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHttp2HealthCheck(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["host"] = + flattenComputeRegionHealthCheckHttp2HealthCheckHost(original["host"], d) + transformed["request_path"] = + flattenComputeRegionHealthCheckHttp2HealthCheckRequestPath(original["requestPath"], d) + transformed["response"] = + flattenComputeRegionHealthCheckHttp2HealthCheckResponse(original["response"], d) + transformed["port"] = + flattenComputeRegionHealthCheckHttp2HealthCheckPort(original["port"], d) + transformed["port_name"] = + flattenComputeRegionHealthCheckHttp2HealthCheckPortName(original["portName"], d) + transformed["proxy_header"] = + flattenComputeRegionHealthCheckHttp2HealthCheckProxyHeader(original["proxyHeader"], d) + transformed["port_specification"] = + flattenComputeRegionHealthCheckHttp2HealthCheckPortSpecification(original["portSpecification"], d) + return []interface{}{transformed} +} +func flattenComputeRegionHealthCheckHttp2HealthCheckHost(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHttp2HealthCheckRequestPath(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHttp2HealthCheckResponse(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHttp2HealthCheckPort(v interface{}, d *schema.ResourceData) 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 flattenComputeRegionHealthCheckHttp2HealthCheckPortName(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHttp2HealthCheckProxyHeader(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckHttp2HealthCheckPortSpecification(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenComputeRegionHealthCheckRegion(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + return NameFromSelfLinkStateFunc(v) +} + +func expandComputeRegionHealthCheckCheckIntervalSec(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHealthyThreshold(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckUnhealthyThreshold(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckTimeoutSec(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttpHealthCheck(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedHost, err := expandComputeRegionHealthCheckHttpHealthCheckHost(original["host"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedHost); val.IsValid() && !isEmptyValue(val) { + transformed["host"] = transformedHost + } + + transformedRequestPath, err := expandComputeRegionHealthCheckHttpHealthCheckRequestPath(original["request_path"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedRequestPath); val.IsValid() && !isEmptyValue(val) { + transformed["requestPath"] = transformedRequestPath + } + + transformedResponse, err := expandComputeRegionHealthCheckHttpHealthCheckResponse(original["response"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedResponse); val.IsValid() && !isEmptyValue(val) { + transformed["response"] = transformedResponse + } + + transformedPort, err := expandComputeRegionHealthCheckHttpHealthCheckPort(original["port"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPort); val.IsValid() && !isEmptyValue(val) { + transformed["port"] = transformedPort + } + + transformedPortName, err := expandComputeRegionHealthCheckHttpHealthCheckPortName(original["port_name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPortName); val.IsValid() && !isEmptyValue(val) { + transformed["portName"] = transformedPortName + } + + transformedProxyHeader, err := expandComputeRegionHealthCheckHttpHealthCheckProxyHeader(original["proxy_header"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedProxyHeader); val.IsValid() && !isEmptyValue(val) { + transformed["proxyHeader"] = transformedProxyHeader + } + + transformedPortSpecification, err := expandComputeRegionHealthCheckHttpHealthCheckPortSpecification(original["port_specification"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPortSpecification); val.IsValid() && !isEmptyValue(val) { + transformed["portSpecification"] = transformedPortSpecification + } + + return transformed, nil +} + +func expandComputeRegionHealthCheckHttpHealthCheckHost(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttpHealthCheckRequestPath(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttpHealthCheckResponse(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttpHealthCheckPort(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttpHealthCheckPortName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttpHealthCheckProxyHeader(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttpHealthCheckPortSpecification(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttpsHealthCheck(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedHost, err := expandComputeRegionHealthCheckHttpsHealthCheckHost(original["host"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedHost); val.IsValid() && !isEmptyValue(val) { + transformed["host"] = transformedHost + } + + transformedRequestPath, err := expandComputeRegionHealthCheckHttpsHealthCheckRequestPath(original["request_path"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedRequestPath); val.IsValid() && !isEmptyValue(val) { + transformed["requestPath"] = transformedRequestPath + } + + transformedResponse, err := expandComputeRegionHealthCheckHttpsHealthCheckResponse(original["response"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedResponse); val.IsValid() && !isEmptyValue(val) { + transformed["response"] = transformedResponse + } + + transformedPort, err := expandComputeRegionHealthCheckHttpsHealthCheckPort(original["port"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPort); val.IsValid() && !isEmptyValue(val) { + transformed["port"] = transformedPort + } + + transformedPortName, err := expandComputeRegionHealthCheckHttpsHealthCheckPortName(original["port_name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPortName); val.IsValid() && !isEmptyValue(val) { + transformed["portName"] = transformedPortName + } + + transformedProxyHeader, err := expandComputeRegionHealthCheckHttpsHealthCheckProxyHeader(original["proxy_header"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedProxyHeader); val.IsValid() && !isEmptyValue(val) { + transformed["proxyHeader"] = transformedProxyHeader + } + + transformedPortSpecification, err := expandComputeRegionHealthCheckHttpsHealthCheckPortSpecification(original["port_specification"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPortSpecification); val.IsValid() && !isEmptyValue(val) { + transformed["portSpecification"] = transformedPortSpecification + } + + return transformed, nil +} + +func expandComputeRegionHealthCheckHttpsHealthCheckHost(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttpsHealthCheckRequestPath(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttpsHealthCheckResponse(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttpsHealthCheckPort(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttpsHealthCheckPortName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttpsHealthCheckProxyHeader(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttpsHealthCheckPortSpecification(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckTcpHealthCheck(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedRequest, err := expandComputeRegionHealthCheckTcpHealthCheckRequest(original["request"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedRequest); val.IsValid() && !isEmptyValue(val) { + transformed["request"] = transformedRequest + } + + transformedResponse, err := expandComputeRegionHealthCheckTcpHealthCheckResponse(original["response"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedResponse); val.IsValid() && !isEmptyValue(val) { + transformed["response"] = transformedResponse + } + + transformedPort, err := expandComputeRegionHealthCheckTcpHealthCheckPort(original["port"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPort); val.IsValid() && !isEmptyValue(val) { + transformed["port"] = transformedPort + } + + transformedPortName, err := expandComputeRegionHealthCheckTcpHealthCheckPortName(original["port_name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPortName); val.IsValid() && !isEmptyValue(val) { + transformed["portName"] = transformedPortName + } + + transformedProxyHeader, err := expandComputeRegionHealthCheckTcpHealthCheckProxyHeader(original["proxy_header"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedProxyHeader); val.IsValid() && !isEmptyValue(val) { + transformed["proxyHeader"] = transformedProxyHeader + } + + transformedPortSpecification, err := expandComputeRegionHealthCheckTcpHealthCheckPortSpecification(original["port_specification"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPortSpecification); val.IsValid() && !isEmptyValue(val) { + transformed["portSpecification"] = transformedPortSpecification + } + + return transformed, nil +} + +func expandComputeRegionHealthCheckTcpHealthCheckRequest(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckTcpHealthCheckResponse(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckTcpHealthCheckPort(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckTcpHealthCheckPortName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckTcpHealthCheckProxyHeader(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckTcpHealthCheckPortSpecification(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckSslHealthCheck(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedRequest, err := expandComputeRegionHealthCheckSslHealthCheckRequest(original["request"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedRequest); val.IsValid() && !isEmptyValue(val) { + transformed["request"] = transformedRequest + } + + transformedResponse, err := expandComputeRegionHealthCheckSslHealthCheckResponse(original["response"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedResponse); val.IsValid() && !isEmptyValue(val) { + transformed["response"] = transformedResponse + } + + transformedPort, err := expandComputeRegionHealthCheckSslHealthCheckPort(original["port"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPort); val.IsValid() && !isEmptyValue(val) { + transformed["port"] = transformedPort + } + + transformedPortName, err := expandComputeRegionHealthCheckSslHealthCheckPortName(original["port_name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPortName); val.IsValid() && !isEmptyValue(val) { + transformed["portName"] = transformedPortName + } + + transformedProxyHeader, err := expandComputeRegionHealthCheckSslHealthCheckProxyHeader(original["proxy_header"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedProxyHeader); val.IsValid() && !isEmptyValue(val) { + transformed["proxyHeader"] = transformedProxyHeader + } + + transformedPortSpecification, err := expandComputeRegionHealthCheckSslHealthCheckPortSpecification(original["port_specification"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPortSpecification); val.IsValid() && !isEmptyValue(val) { + transformed["portSpecification"] = transformedPortSpecification + } + + return transformed, nil +} + +func expandComputeRegionHealthCheckSslHealthCheckRequest(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckSslHealthCheckResponse(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckSslHealthCheckPort(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckSslHealthCheckPortName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckSslHealthCheckProxyHeader(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckSslHealthCheckPortSpecification(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttp2HealthCheck(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedHost, err := expandComputeRegionHealthCheckHttp2HealthCheckHost(original["host"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedHost); val.IsValid() && !isEmptyValue(val) { + transformed["host"] = transformedHost + } + + transformedRequestPath, err := expandComputeRegionHealthCheckHttp2HealthCheckRequestPath(original["request_path"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedRequestPath); val.IsValid() && !isEmptyValue(val) { + transformed["requestPath"] = transformedRequestPath + } + + transformedResponse, err := expandComputeRegionHealthCheckHttp2HealthCheckResponse(original["response"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedResponse); val.IsValid() && !isEmptyValue(val) { + transformed["response"] = transformedResponse + } + + transformedPort, err := expandComputeRegionHealthCheckHttp2HealthCheckPort(original["port"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPort); val.IsValid() && !isEmptyValue(val) { + transformed["port"] = transformedPort + } + + transformedPortName, err := expandComputeRegionHealthCheckHttp2HealthCheckPortName(original["port_name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPortName); val.IsValid() && !isEmptyValue(val) { + transformed["portName"] = transformedPortName + } + + transformedProxyHeader, err := expandComputeRegionHealthCheckHttp2HealthCheckProxyHeader(original["proxy_header"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedProxyHeader); val.IsValid() && !isEmptyValue(val) { + transformed["proxyHeader"] = transformedProxyHeader + } + + transformedPortSpecification, err := expandComputeRegionHealthCheckHttp2HealthCheckPortSpecification(original["port_specification"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPortSpecification); val.IsValid() && !isEmptyValue(val) { + transformed["portSpecification"] = transformedPortSpecification + } + + return transformed, nil +} + +func expandComputeRegionHealthCheckHttp2HealthCheckHost(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttp2HealthCheckRequestPath(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttp2HealthCheckResponse(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttp2HealthCheckPort(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttp2HealthCheckPortName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttp2HealthCheckProxyHeader(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckHttp2HealthCheckPortSpecification(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandComputeRegionHealthCheckRegion(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + f, err := parseGlobalFieldValue("regions", v.(string), "project", d, config, true) + if err != nil { + return nil, fmt.Errorf("Invalid value for region: %s", err) + } + return f.RelativeLink(), nil +} + +func resourceComputeRegionHealthCheckEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) { + + if _, ok := d.GetOk("http_health_check"); ok { + hc := d.Get("http_health_check").([]interface{})[0] + ps := hc.(map[string]interface{})["port_specification"] + pn := hc.(map[string]interface{})["port_name"] + + if ps == "USE_FIXED_PORT" || (ps == "" && pn == "") { + m := obj["httpHealthCheck"].(map[string]interface{}) + if m["port"] == nil { + m["port"] = 80 + } + } + obj["type"] = "HTTP" + return obj, nil + } + if _, ok := d.GetOk("https_health_check"); ok { + hc := d.Get("https_health_check").([]interface{})[0] + ps := hc.(map[string]interface{})["port_specification"] + pn := hc.(map[string]interface{})["port_name"] + + if ps == "USE_FIXED_PORT" || (ps == "" && pn == "") { + m := obj["httpsHealthCheck"].(map[string]interface{}) + if m["port"] == nil { + m["port"] = 443 + } + } + obj["type"] = "HTTPS" + return obj, nil + } + if _, ok := d.GetOk("http2_health_check"); ok { + hc := d.Get("http2_health_check").([]interface{})[0] + ps := hc.(map[string]interface{})["port_specification"] + pn := hc.(map[string]interface{})["port_name"] + + if ps == "USE_FIXED_PORT" || (ps == "" && pn == "") { + m := obj["http2HealthCheck"].(map[string]interface{}) + if m["port"] == nil { + m["port"] = 443 + } + } + obj["type"] = "HTTP2" + return obj, nil + } + if _, ok := d.GetOk("tcp_health_check"); ok { + hc := d.Get("tcp_health_check").([]interface{})[0] + ps := hc.(map[string]interface{})["port_specification"] + pn := hc.(map[string]interface{})["port_name"] + + if ps == "USE_FIXED_PORT" || (ps == "" && pn == "") { + m := obj["tcpHealthCheck"].(map[string]interface{}) + if m["port"] == nil { + m["port"] = 80 + } + } + obj["type"] = "TCP" + return obj, nil + } + if _, ok := d.GetOk("ssl_health_check"); ok { + hc := d.Get("ssl_health_check").([]interface{})[0] + ps := hc.(map[string]interface{})["port_specification"] + pn := hc.(map[string]interface{})["port_name"] + + if ps == "USE_FIXED_PORT" || (ps == "" && pn == "") { + m := obj["sslHealthCheck"].(map[string]interface{}) + if m["port"] == nil { + m["port"] = 443 + } + } + obj["type"] = "SSL" + return obj, nil + } + + return nil, fmt.Errorf("error in HealthCheck %s: No health check block specified.", d.Get("name").(string)) +} diff --git a/google/resource_compute_region_health_check_generated_test.go b/google/resource_compute_region_health_check_generated_test.go new file mode 100644 index 00000000000..b4f64ff1429 --- /dev/null +++ b/google/resource_compute_region_health_check_generated_test.go @@ -0,0 +1,478 @@ +// ---------------------------------------------------------------------------- +// +// *** 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. +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "fmt" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +func TestAccComputeRegionHealthCheck_regionHealthCheckTcpExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRegionHealthCheckDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionHealthCheck_regionHealthCheckTcpExample(context), + }, + { + ResourceName: "google_compute_region_health_check.tcp-region-health-check", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccComputeRegionHealthCheck_regionHealthCheckTcpExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_region_health_check" "tcp-region-health-check" { + name = "tcp-region-health-check%{random_suffix}" + + timeout_sec = 1 + check_interval_sec = 1 + + tcp_health_check { + port = "80" + } +} +`, context) +} + +func TestAccComputeRegionHealthCheck_regionHealthCheckTcpFullExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRegionHealthCheckDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionHealthCheck_regionHealthCheckTcpFullExample(context), + }, + { + ResourceName: "google_compute_region_health_check.tcp-region-health-check", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccComputeRegionHealthCheck_regionHealthCheckTcpFullExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_region_health_check" "tcp-region-health-check" { + name = "tcp-region-health-check%{random_suffix}" + description = "Health check via tcp" + + timeout_sec = 1 + check_interval_sec = 1 + healthy_threshold = 4 + unhealthy_threshold = 5 + + tcp_health_check { + port_name = "health-check-port" + port_specification = "USE_NAMED_PORT" + request = "ARE YOU HEALTHY?" + proxy_header = "NONE" + response = "I AM HEALTHY" + } +} +`, context) +} + +func TestAccComputeRegionHealthCheck_regionHealthCheckSslExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRegionHealthCheckDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionHealthCheck_regionHealthCheckSslExample(context), + }, + { + ResourceName: "google_compute_region_health_check.ssl-region-health-check", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccComputeRegionHealthCheck_regionHealthCheckSslExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_region_health_check" "ssl-region-health-check" { + name = "ssl-region-health-check%{random_suffix}" + + timeout_sec = 1 + check_interval_sec = 1 + + ssl_health_check { + port = "443" + } +} +`, context) +} + +func TestAccComputeRegionHealthCheck_regionHealthCheckSslFullExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRegionHealthCheckDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionHealthCheck_regionHealthCheckSslFullExample(context), + }, + { + ResourceName: "google_compute_region_health_check.ssl-region-health-check", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccComputeRegionHealthCheck_regionHealthCheckSslFullExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_region_health_check" "ssl-region-health-check" { + name = "ssl-region-health-check%{random_suffix}" + description = "Health check via ssl" + + timeout_sec = 1 + check_interval_sec = 1 + healthy_threshold = 4 + unhealthy_threshold = 5 + + ssl_health_check { + port_name = "health-check-port" + port_specification = "USE_NAMED_PORT" + request = "ARE YOU HEALTHY?" + proxy_header = "NONE" + response = "I AM HEALTHY" + } +} +`, context) +} + +func TestAccComputeRegionHealthCheck_regionHealthCheckHttpExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRegionHealthCheckDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionHealthCheck_regionHealthCheckHttpExample(context), + }, + { + ResourceName: "google_compute_region_health_check.http-region-health-check", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccComputeRegionHealthCheck_regionHealthCheckHttpExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_region_health_check" "http-region-health-check" { + name = "http-region-health-check%{random_suffix}" + + timeout_sec = 1 + check_interval_sec = 1 + + http_health_check { + port = "80" + } +} +`, context) +} + +func TestAccComputeRegionHealthCheck_regionHealthCheckHttpFullExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRegionHealthCheckDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionHealthCheck_regionHealthCheckHttpFullExample(context), + }, + { + ResourceName: "google_compute_region_health_check.http-region-health-check", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccComputeRegionHealthCheck_regionHealthCheckHttpFullExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_region_health_check" "http-region-health-check" { + name = "http-region-health-check%{random_suffix}" + description = "Health check via http" + + timeout_sec = 1 + check_interval_sec = 1 + healthy_threshold = 4 + unhealthy_threshold = 5 + + http_health_check { + port_name = "health-check-port" + port_specification = "USE_NAMED_PORT" + host = "1.2.3.4" + request_path = "/mypath" + proxy_header = "NONE" + response = "I AM HEALTHY" + } +} +`, context) +} + +func TestAccComputeRegionHealthCheck_regionHealthCheckHttpsExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRegionHealthCheckDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionHealthCheck_regionHealthCheckHttpsExample(context), + }, + { + ResourceName: "google_compute_region_health_check.https-region-health-check", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccComputeRegionHealthCheck_regionHealthCheckHttpsExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_region_health_check" "https-region-health-check" { + name = "https-region-health-check%{random_suffix}" + + timeout_sec = 1 + check_interval_sec = 1 + + https_health_check { + port = "443" + } +} +`, context) +} + +func TestAccComputeRegionHealthCheck_regionHealthCheckHttpsFullExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRegionHealthCheckDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionHealthCheck_regionHealthCheckHttpsFullExample(context), + }, + { + ResourceName: "google_compute_region_health_check.https-region-health-check", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccComputeRegionHealthCheck_regionHealthCheckHttpsFullExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_region_health_check" "https-region-health-check" { + name = "https-region-health-check%{random_suffix}" + description = "Health check via https" + + timeout_sec = 1 + check_interval_sec = 1 + healthy_threshold = 4 + unhealthy_threshold = 5 + + https_health_check { + port_name = "health-check-port" + port_specification = "USE_NAMED_PORT" + host = "1.2.3.4" + request_path = "/mypath" + proxy_header = "NONE" + response = "I AM HEALTHY" + } +} +`, context) +} + +func TestAccComputeRegionHealthCheck_regionHealthCheckHttp2Example(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRegionHealthCheckDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionHealthCheck_regionHealthCheckHttp2Example(context), + }, + { + ResourceName: "google_compute_region_health_check.http2-region-health-check", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccComputeRegionHealthCheck_regionHealthCheckHttp2Example(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_region_health_check" "http2-region-health-check" { + name = "http2-region-health-check%{random_suffix}" + + timeout_sec = 1 + check_interval_sec = 1 + + http2_health_check { + port = "443" + } +} +`, context) +} + +func TestAccComputeRegionHealthCheck_regionHealthCheckHttp2FullExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRegionHealthCheckDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionHealthCheck_regionHealthCheckHttp2FullExample(context), + }, + { + ResourceName: "google_compute_region_health_check.http2-region-health-check", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccComputeRegionHealthCheck_regionHealthCheckHttp2FullExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_region_health_check" "http2-region-health-check" { + name = "http2-region-health-check%{random_suffix}" + description = "Health check via http2" + + timeout_sec = 1 + check_interval_sec = 1 + healthy_threshold = 4 + unhealthy_threshold = 5 + + http2_health_check { + port_name = "health-check-port" + port_specification = "USE_NAMED_PORT" + host = "1.2.3.4" + request_path = "/mypath" + proxy_header = "NONE" + response = "I AM HEALTHY" + } +} +`, context) +} + +func testAccCheckComputeRegionHealthCheckDestroy(s *terraform.State) error { + for name, rs := range s.RootModule().Resources { + if rs.Type != "google_compute_region_health_check" { + continue + } + if strings.HasPrefix(name, "data.") { + continue + } + + config := testAccProvider.Meta().(*Config) + + url, err := replaceVarsForTest(config, rs, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/healthChecks/{{name}}") + if err != nil { + return err + } + + _, err = sendRequest(config, "GET", "", url, nil) + if err == nil { + return fmt.Errorf("ComputeRegionHealthCheck still exists at %s", url) + } + } + + return nil +} diff --git a/google/resource_compute_region_health_check_test.go b/google/resource_compute_region_health_check_test.go index 71664db3c87..9d255e0b398 100644 --- a/google/resource_compute_region_health_check_test.go +++ b/google/resource_compute_region_health_check_test.go @@ -1 +1,342 @@ package google + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccComputeRegionHealthCheck_tcp_update(t *testing.T) { + t.Parallel() + + hckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRegionHealthCheckDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionHealthCheck_tcp(hckName), + }, + { + ResourceName: "google_compute_region_health_check.foobar", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccComputeRegionHealthCheck_tcp_update(hckName), + }, + { + ResourceName: "google_compute_region_health_check.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccComputeRegionHealthCheck_ssl_port_spec(t *testing.T) { + t.Parallel() + + hckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRegionHealthCheckDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionHealthCheck_ssl_fixed_port(hckName), + }, + { + ResourceName: "google_compute_region_health_check.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccComputeRegionHealthCheck_http_port_spec(t *testing.T) { + t.Parallel() + + hckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRegionHealthCheckDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionHealthCheck_http_port_spec(hckName), + ExpectError: regexp.MustCompile("Error in http_health_check: Must specify port_name when using USE_NAMED_PORT as port_specification."), + }, + { + Config: testAccComputeRegionHealthCheck_http_named_port(hckName), + }, + { + ResourceName: "google_compute_region_health_check.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccComputeRegionHealthCheck_https_serving_port(t *testing.T) { + t.Parallel() + + hckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRegionHealthCheckDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionHealthCheck_https_serving_port(hckName), + }, + { + ResourceName: "google_compute_region_health_check.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccComputeRegionHealthCheck_typeTransition(t *testing.T) { + t.Parallel() + + hckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRegionHealthCheckDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionHealthCheck_https(hckName), + }, + { + Config: testAccComputeRegionHealthCheck_http(hckName), + }, + { + Config: testAccComputeRegionHealthCheck_ssl(hckName), + }, + { + Config: testAccComputeRegionHealthCheck_tcp(hckName), + }, + { + Config: testAccComputeRegionHealthCheck_http2(hckName), + }, + { + Config: testAccComputeRegionHealthCheck_https(hckName), + }, + }, + }) +} + +func TestAccComputeRegionHealthCheck_tcpAndSsl_shouldFail(t *testing.T) { + t.Parallel() + + hckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRegionHealthCheckDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionHealthCheck_tcpAndSsl_shouldFail(hckName), + ExpectError: regexp.MustCompile("only one of `http2_health_check,http_health_check,https_health_check,ssl_health_check,tcp_health_check` can be specified"), + }, + }, + }) +} + +func testAccComputeRegionHealthCheck_tcp(hckName string) string { + return fmt.Sprintf(` +resource "google_compute_region_health_check" "foobar" { + check_interval_sec = 3 + description = "Resource created for Terraform acceptance testing" + healthy_threshold = 3 + name = "health-test-%s" + timeout_sec = 2 + unhealthy_threshold = 3 + tcp_health_check { + port = 443 + } +} +`, hckName) +} + +func testAccComputeRegionHealthCheck_tcp_update(hckName string) string { + return fmt.Sprintf(` +resource "google_compute_region_health_check" "foobar" { + check_interval_sec = 3 + description = "Resource updated for Terraform acceptance testing" + healthy_threshold = 10 + name = "health-test-%s" + timeout_sec = 2 + unhealthy_threshold = 10 + tcp_health_check { + port = "8080" + } +} +`, hckName) +} + +func testAccComputeRegionHealthCheck_ssl(hckName string) string { + return fmt.Sprintf(` +resource "google_compute_region_health_check" "foobar" { + check_interval_sec = 3 + description = "Resource created for Terraform acceptance testing" + healthy_threshold = 3 + name = "health-test-%s" + timeout_sec = 2 + unhealthy_threshold = 3 + ssl_health_check { + port = "443" + } +} +`, hckName) +} + +func testAccComputeRegionHealthCheck_ssl_fixed_port(hckName string) string { + return fmt.Sprintf(` +resource "google_compute_region_health_check" "foobar" { + check_interval_sec = 3 + description = "Resource created for Terraform acceptance testing" + healthy_threshold = 3 + name = "health-test-%s" + timeout_sec = 2 + unhealthy_threshold = 3 + ssl_health_check { + port = "443" + port_specification = "USE_FIXED_PORT" + } +} +`, hckName) +} + +func testAccComputeRegionHealthCheck_http(hckName string) string { + return fmt.Sprintf(` +resource "google_compute_region_health_check" "foobar" { + check_interval_sec = 3 + description = "Resource created for Terraform acceptance testing" + healthy_threshold = 3 + name = "health-test-%s" + timeout_sec = 2 + unhealthy_threshold = 3 + http_health_check { + port = "80" + } +} +`, hckName) +} + +func testAccComputeRegionHealthCheck_http_port_spec(hckName string) string { + return fmt.Sprintf(` +resource "google_compute_region_health_check" "foobar" { + check_interval_sec = 3 + description = "Resource created for Terraform acceptance testing" + healthy_threshold = 3 + name = "health-test-%s" + timeout_sec = 2 + unhealthy_threshold = 3 + http_health_check { + port_specification = "USE_NAMED_PORT" + } +} +`, hckName) +} + +func testAccComputeRegionHealthCheck_http_named_port(hckName string) string { + return fmt.Sprintf(` +resource "google_compute_region_health_check" "foobar" { + check_interval_sec = 3 + description = "Resource created for Terraform acceptance testing" + healthy_threshold = 3 + name = "health-test-%s" + timeout_sec = 2 + unhealthy_threshold = 3 + http_health_check { + port_name = "http" + port_specification = "USE_NAMED_PORT" + } +} +`, hckName) +} + +func testAccComputeRegionHealthCheck_https(hckName string) string { + return fmt.Sprintf(` +resource "google_compute_region_health_check" "foobar" { + check_interval_sec = 3 + description = "Resource created for Terraform acceptance testing" + healthy_threshold = 3 + name = "health-test-%s" + timeout_sec = 2 + unhealthy_threshold = 3 + https_health_check { + port = "443" + } +} +`, hckName) +} + +func testAccComputeRegionHealthCheck_https_serving_port(hckName string) string { + return fmt.Sprintf(` +resource "google_compute_region_health_check" "foobar" { + check_interval_sec = 3 + description = "Resource created for Terraform acceptance testing" + healthy_threshold = 3 + name = "health-test-%s" + timeout_sec = 2 + unhealthy_threshold = 3 + https_health_check { + port_specification = "USE_SERVING_PORT" + } +} +`, hckName) +} + +func testAccComputeRegionHealthCheck_http2(hckName string) string { + return fmt.Sprintf(` +resource "google_compute_region_health_check" "foobar" { + check_interval_sec = 3 + description = "Resource created for Terraform acceptance testing" + healthy_threshold = 3 + name = "health-test-%s" + timeout_sec = 2 + unhealthy_threshold = 3 + http2_health_check { + port = "443" + } +} +`, hckName) +} + +func testAccComputeRegionHealthCheck_tcpAndSsl_shouldFail(hckName string) string { + return fmt.Sprintf(` +resource "google_compute_region_health_check" "foobar" { + check_interval_sec = 3 + description = "Resource created for Terraform acceptance testing" + healthy_threshold = 3 + name = "health-test-%s" + timeout_sec = 2 + unhealthy_threshold = 3 + + tcp_health_check { + port = 443 + } + ssl_health_check { + port = 443 + } +} +`, hckName) +} diff --git a/website/docs/r/compute_region_health_check.html.markdown b/website/docs/r/compute_region_health_check.html.markdown new file mode 100644 index 00000000000..d6703c5fe0f --- /dev/null +++ b/website/docs/r/compute_region_health_check.html.markdown @@ -0,0 +1,622 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** 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. +# +# ---------------------------------------------------------------------------- +subcategory: "Compute Engine" +layout: "google" +page_title: "Google: google_compute_region_health_check" +sidebar_current: "docs-google-compute-region-health-check" +description: |- + Health Checks determine whether instances are responsive and able to do work. +--- + +# google\_compute\_region\_health\_check + +Health Checks determine whether instances are responsive and able to do work. +They are an important part of a comprehensive load balancing configuration, +as they enable monitoring instances behind load balancers. + +Health Checks poll instances at a specified interval. Instances that +do not respond successfully to some number of probes in a row are marked +as unhealthy. No new connections are sent to unhealthy instances, +though existing connections will continue. The health check will +continue to poll unhealthy instances. If an instance later responds +successfully to some number of consecutive probes, it is marked +healthy again and can receive new connections. + + +To get more information about RegionHealthCheck, see: + +* [API documentation](https://cloud.google.com/compute/docs/reference/rest/beta/regionHealthChecks) +* How-to Guides + * [Official Documentation](https://cloud.google.com/load-balancing/docs/health-checks) + + +## Example Usage - Region Health Check Tcp + + +```hcl +resource "google_compute_region_health_check" "tcp-region-health-check" { + name = "tcp-region-health-check" + + timeout_sec = 1 + check_interval_sec = 1 + + tcp_health_check { + port = "80" + } +} +``` + +## Example Usage - Region Health Check Tcp Full + + +```hcl +resource "google_compute_region_health_check" "tcp-region-health-check" { + name = "tcp-region-health-check" + description = "Health check via tcp" + + timeout_sec = 1 + check_interval_sec = 1 + healthy_threshold = 4 + unhealthy_threshold = 5 + + tcp_health_check { + port_name = "health-check-port" + port_specification = "USE_NAMED_PORT" + request = "ARE YOU HEALTHY?" + proxy_header = "NONE" + response = "I AM HEALTHY" + } +} +``` + +## Example Usage - Region Health Check Ssl + + +```hcl +resource "google_compute_region_health_check" "ssl-region-health-check" { + name = "ssl-region-health-check" + + timeout_sec = 1 + check_interval_sec = 1 + + ssl_health_check { + port = "443" + } +} +``` + +## Example Usage - Region Health Check Ssl Full + + +```hcl +resource "google_compute_region_health_check" "ssl-region-health-check" { + name = "ssl-region-health-check" + description = "Health check via ssl" + + timeout_sec = 1 + check_interval_sec = 1 + healthy_threshold = 4 + unhealthy_threshold = 5 + + ssl_health_check { + port_name = "health-check-port" + port_specification = "USE_NAMED_PORT" + request = "ARE YOU HEALTHY?" + proxy_header = "NONE" + response = "I AM HEALTHY" + } +} +``` + +## Example Usage - Region Health Check Http + + +```hcl +resource "google_compute_region_health_check" "http-region-health-check" { + name = "http-region-health-check" + + timeout_sec = 1 + check_interval_sec = 1 + + http_health_check { + port = "80" + } +} +``` + +## Example Usage - Region Health Check Http Full + + +```hcl +resource "google_compute_region_health_check" "http-region-health-check" { + name = "http-region-health-check" + description = "Health check via http" + + timeout_sec = 1 + check_interval_sec = 1 + healthy_threshold = 4 + unhealthy_threshold = 5 + + http_health_check { + port_name = "health-check-port" + port_specification = "USE_NAMED_PORT" + host = "1.2.3.4" + request_path = "/mypath" + proxy_header = "NONE" + response = "I AM HEALTHY" + } +} +``` + +## Example Usage - Region Health Check Https + + +```hcl +resource "google_compute_region_health_check" "https-region-health-check" { + name = "https-region-health-check" + + timeout_sec = 1 + check_interval_sec = 1 + + https_health_check { + port = "443" + } +} +``` + +## Example Usage - Region Health Check Https Full + + +```hcl +resource "google_compute_region_health_check" "https-region-health-check" { + name = "https-region-health-check" + description = "Health check via https" + + timeout_sec = 1 + check_interval_sec = 1 + healthy_threshold = 4 + unhealthy_threshold = 5 + + https_health_check { + port_name = "health-check-port" + port_specification = "USE_NAMED_PORT" + host = "1.2.3.4" + request_path = "/mypath" + proxy_header = "NONE" + response = "I AM HEALTHY" + } +} +``` + +## Example Usage - Region Health Check Http2 + + +```hcl +resource "google_compute_region_health_check" "http2-region-health-check" { + name = "http2-region-health-check" + + timeout_sec = 1 + check_interval_sec = 1 + + http2_health_check { + port = "443" + } +} +``` + +## Example Usage - Region Health Check Http2 Full + + +```hcl +resource "google_compute_region_health_check" "http2-region-health-check" { + name = "http2-region-health-check" + description = "Health check via http2" + + timeout_sec = 1 + check_interval_sec = 1 + healthy_threshold = 4 + unhealthy_threshold = 5 + + http2_health_check { + port_name = "health-check-port" + port_specification = "USE_NAMED_PORT" + host = "1.2.3.4" + request_path = "/mypath" + proxy_header = "NONE" + response = "I AM HEALTHY" + } +} +``` + +## Argument Reference + +The following arguments are supported: + + +* `name` - + (Required) + Name of the resource. Provided by the client when the resource is + created. The name must be 1-63 characters long, and comply with + RFC1035. Specifically, the name must be 1-63 characters long and + match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means + the first character must be a lowercase letter, and all following + characters must be a dash, lowercase letter, or digit, except the + last character, which cannot be a dash. + + +- - - + + +* `check_interval_sec` - + (Optional) + How often (in seconds) to send a health check. The default value is 5 + seconds. + +* `description` - + (Optional) + An optional description of this resource. Provide this property when + you create the resource. + +* `healthy_threshold` - + (Optional) + A so-far unhealthy instance will be marked healthy after this many + consecutive successes. The default value is 2. + +* `unhealthy_threshold` - + (Optional) + A so-far healthy instance will be marked unhealthy after this many + consecutive failures. The default value is 2. + +* `timeout_sec` - + (Optional) + How long (in seconds) to wait before claiming failure. + The default value is 5 seconds. It is invalid for timeoutSec to have + greater value than checkIntervalSec. + +* `http_health_check` - + (Optional) + A nested object resource Structure is documented below. + +* `https_health_check` - + (Optional) + A nested object resource Structure is documented below. + +* `tcp_health_check` - + (Optional) + A nested object resource Structure is documented below. + +* `ssl_health_check` - + (Optional) + A nested object resource Structure is documented below. + +* `http2_health_check` - + (Optional) + A nested object resource Structure is documented below. + +* `region` - + (Optional) + The Region in which the created health check should reside. + If it is not provided, the provider region is used. + +* `project` - (Optional) The ID of the project in which the resource belongs. + If it is not provided, the provider project is used. + + +The `http_health_check` block supports: + +* `host` - + (Optional) + The value of the host header in the HTTP health check request. + If left empty (default value), the public IP on behalf of which this health + check is performed will be used. + +* `request_path` - + (Optional) + The request path of the HTTP health check request. + The default value is /. + +* `response` - + (Optional) + The bytes to match against the beginning of the response data. If left empty + (the default value), any response will indicate health. The response data + can only be ASCII. + +* `port` - + (Optional) + The TCP port number for the HTTP health check request. + The default value is 80. + +* `port_name` - + (Optional) + Port name as defined in InstanceGroup#NamedPort#name. If both port and + port_name are defined, port takes precedence. + +* `proxy_header` - + (Optional) + Specifies the type of proxy header to append before sending data to the + backend, either NONE or PROXY_V1. The default is NONE. + +* `port_specification` - + (Optional) + Specifies how port is selected for health checking, can be one of the + following values: + * `USE_FIXED_PORT`: The port number in `port` is used for health checking. + * `USE_NAMED_PORT`: The `portName` is used for health checking. + * `USE_SERVING_PORT`: For NetworkEndpointGroup, the port specified for each + network endpoint is used for health checking. For other backends, the + port or named port specified in the Backend Service is used for health + checking. + If not specified, HTTP health check follows behavior specified in `port` and + `portName` fields. + +The `https_health_check` block supports: + +* `host` - + (Optional) + The value of the host header in the HTTPS health check request. + If left empty (default value), the public IP on behalf of which this health + check is performed will be used. + +* `request_path` - + (Optional) + The request path of the HTTPS health check request. + The default value is /. + +* `response` - + (Optional) + The bytes to match against the beginning of the response data. If left empty + (the default value), any response will indicate health. The response data + can only be ASCII. + +* `port` - + (Optional) + The TCP port number for the HTTPS health check request. + The default value is 443. + +* `port_name` - + (Optional) + Port name as defined in InstanceGroup#NamedPort#name. If both port and + port_name are defined, port takes precedence. + +* `proxy_header` - + (Optional) + Specifies the type of proxy header to append before sending data to the + backend, either NONE or PROXY_V1. The default is NONE. + +* `port_specification` - + (Optional) + Specifies how port is selected for health checking, can be one of the + following values: + * `USE_FIXED_PORT`: The port number in `port` is used for health checking. + * `USE_NAMED_PORT`: The `portName` is used for health checking. + * `USE_SERVING_PORT`: For NetworkEndpointGroup, the port specified for each + network endpoint is used for health checking. For other backends, the + port or named port specified in the Backend Service is used for health + checking. + If not specified, HTTPS health check follows behavior specified in `port` and + `portName` fields. + +The `tcp_health_check` block supports: + +* `request` - + (Optional) + The application data to send once the TCP connection has been + established (default value is empty). If both request and response are + empty, the connection establishment alone will indicate health. The request + data can only be ASCII. + +* `response` - + (Optional) + The bytes to match against the beginning of the response data. If left empty + (the default value), any response will indicate health. The response data + can only be ASCII. + +* `port` - + (Optional) + The TCP port number for the TCP health check request. + The default value is 80. + +* `port_name` - + (Optional) + Port name as defined in InstanceGroup#NamedPort#name. If both port and + port_name are defined, port takes precedence. + +* `proxy_header` - + (Optional) + Specifies the type of proxy header to append before sending data to the + backend, either NONE or PROXY_V1. The default is NONE. + +* `port_specification` - + (Optional) + Specifies how port is selected for health checking, can be one of the + following values: + * `USE_FIXED_PORT`: The port number in `port` is used for health checking. + * `USE_NAMED_PORT`: The `portName` is used for health checking. + * `USE_SERVING_PORT`: For NetworkEndpointGroup, the port specified for each + network endpoint is used for health checking. For other backends, the + port or named port specified in the Backend Service is used for health + checking. + If not specified, TCP health check follows behavior specified in `port` and + `portName` fields. + +The `ssl_health_check` block supports: + +* `request` - + (Optional) + The application data to send once the SSL connection has been + established (default value is empty). If both request and response are + empty, the connection establishment alone will indicate health. The request + data can only be ASCII. + +* `response` - + (Optional) + The bytes to match against the beginning of the response data. If left empty + (the default value), any response will indicate health. The response data + can only be ASCII. + +* `port` - + (Optional) + The TCP port number for the SSL health check request. + The default value is 443. + +* `port_name` - + (Optional) + Port name as defined in InstanceGroup#NamedPort#name. If both port and + port_name are defined, port takes precedence. + +* `proxy_header` - + (Optional) + Specifies the type of proxy header to append before sending data to the + backend, either NONE or PROXY_V1. The default is NONE. + +* `port_specification` - + (Optional) + Specifies how port is selected for health checking, can be one of the + following values: + * `USE_FIXED_PORT`: The port number in `port` is used for health checking. + * `USE_NAMED_PORT`: The `portName` is used for health checking. + * `USE_SERVING_PORT`: For NetworkEndpointGroup, the port specified for each + network endpoint is used for health checking. For other backends, the + port or named port specified in the Backend Service is used for health + checking. + If not specified, SSL health check follows behavior specified in `port` and + `portName` fields. + +The `http2_health_check` block supports: + +* `host` - + (Optional) + The value of the host header in the HTTP2 health check request. + If left empty (default value), the public IP on behalf of which this health + check is performed will be used. + +* `request_path` - + (Optional) + The request path of the HTTP2 health check request. + The default value is /. + +* `response` - + (Optional) + The bytes to match against the beginning of the response data. If left empty + (the default value), any response will indicate health. The response data + can only be ASCII. + +* `port` - + (Optional) + The TCP port number for the HTTP2 health check request. + The default value is 443. + +* `port_name` - + (Optional) + Port name as defined in InstanceGroup#NamedPort#name. If both port and + port_name are defined, port takes precedence. + +* `proxy_header` - + (Optional) + Specifies the type of proxy header to append before sending data to the + backend, either NONE or PROXY_V1. The default is NONE. + +* `port_specification` - + (Optional) + Specifies how port is selected for health checking, can be one of the + following values: + * `USE_FIXED_PORT`: The port number in `port` is used for health checking. + * `USE_NAMED_PORT`: The `portName` is used for health checking. + * `USE_SERVING_PORT`: For NetworkEndpointGroup, the port specified for each + network endpoint is used for health checking. For other backends, the + port or named port specified in the Backend Service is used for health + checking. + If not specified, HTTP2 health check follows behavior specified in `port` and + `portName` fields. + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are exported: + + +* `creation_timestamp` - + Creation timestamp in RFC3339 text format. + +* `type` - + The type of the health check. One of HTTP, HTTP2, HTTPS, TCP, or SSL. +* `self_link` - The URI of the created resource. + + +## Timeouts + +This resource provides the following +[Timeouts](/docs/configuration/resources.html#timeouts) configuration options: + +- `create` - Default is 4 minutes. +- `update` - Default is 4 minutes. +- `delete` - Default is 4 minutes. + +## Import + +RegionHealthCheck can be imported using any of these accepted formats: + +``` +$ terraform import google_compute_region_health_check.default projects/{{project}}/regions/{{region}}/healthChecks/{{name}} +$ terraform import google_compute_region_health_check.default {{project}}/{{region}}/{{name}} +$ terraform import google_compute_region_health_check.default {{region}}/{{name}} +$ terraform import google_compute_region_health_check.default {{name}} +``` + +-> If you're importing a resource with beta features, make sure to include `-provider=google-beta` +as an argument so that Terraform uses the correct provider to import your resource. + +## User Project Overrides + +This resource supports [User Project Overrides](https://www.terraform.io/docs/providers/google/guides/provider_reference.html#user_project_override).