Skip to content

googleComputeHealthCheck

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.

\~>NOTE: Legacy HTTP(S) health checks must be used for target pool-based network load balancers. See the official guide for choosing a type of health check.

To get more information about HealthCheck, see:

Example Usage - Health Check Tcp

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.computeHealthCheck.ComputeHealthCheck(this, "tcp-health-check", {
  check_interval_sec: 1,
  name: "tcp-health-check",
  tcp_health_check: [
    {
      port: "80",
    },
  ],
  timeout_sec: 1,
});

Example Usage - Health Check Tcp Full

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.computeHealthCheck.ComputeHealthCheck(this, "tcp-health-check", {
  check_interval_sec: 1,
  description: "Health check via tcp",
  healthy_threshold: 4,
  name: "tcp-health-check",
  tcp_health_check: [
    {
      port_name: "health-check-port",
      port_specification: "USE_NAMED_PORT",
      proxy_header: "NONE",
      request: "ARE YOU HEALTHY?",
      response: "I AM HEALTHY",
    },
  ],
  timeout_sec: 1,
  unhealthy_threshold: 5,
});

Example Usage - Health Check Ssl

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.computeHealthCheck.ComputeHealthCheck(this, "ssl-health-check", {
  check_interval_sec: 1,
  name: "ssl-health-check",
  ssl_health_check: [
    {
      port: "443",
    },
  ],
  timeout_sec: 1,
});

Example Usage - Health Check Ssl Full

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.computeHealthCheck.ComputeHealthCheck(this, "ssl-health-check", {
  check_interval_sec: 1,
  description: "Health check via ssl",
  healthy_threshold: 4,
  name: "ssl-health-check",
  ssl_health_check: [
    {
      port_name: "health-check-port",
      port_specification: "USE_NAMED_PORT",
      proxy_header: "NONE",
      request: "ARE YOU HEALTHY?",
      response: "I AM HEALTHY",
    },
  ],
  timeout_sec: 1,
  unhealthy_threshold: 5,
});

Example Usage - Health Check Http

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.computeHealthCheck.ComputeHealthCheck(this, "http-health-check", {
  check_interval_sec: 1,
  http_health_check: [
    {
      port: 80,
    },
  ],
  name: "http-health-check",
  timeout_sec: 1,
});

Example Usage - Health Check Http Full

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.computeHealthCheck.ComputeHealthCheck(this, "http-health-check", {
  check_interval_sec: 1,
  description: "Health check via http",
  healthy_threshold: 4,
  http_health_check: [
    {
      host: "1.2.3.4",
      port_name: "health-check-port",
      port_specification: "USE_NAMED_PORT",
      proxy_header: "NONE",
      request_path: "/mypath",
      response: "I AM HEALTHY",
    },
  ],
  name: "http-health-check",
  timeout_sec: 1,
  unhealthy_threshold: 5,
});

Example Usage - Health Check Https

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.computeHealthCheck.ComputeHealthCheck(this, "https-health-check", {
  check_interval_sec: 1,
  https_health_check: [
    {
      port: "443",
    },
  ],
  name: "https-health-check",
  timeout_sec: 1,
});

Example Usage - Health Check Https Full

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.computeHealthCheck.ComputeHealthCheck(this, "https-health-check", {
  check_interval_sec: 1,
  description: "Health check via https",
  healthy_threshold: 4,
  https_health_check: [
    {
      host: "1.2.3.4",
      port_name: "health-check-port",
      port_specification: "USE_NAMED_PORT",
      proxy_header: "NONE",
      request_path: "/mypath",
      response: "I AM HEALTHY",
    },
  ],
  name: "https-health-check",
  timeout_sec: 1,
  unhealthy_threshold: 5,
});

Example Usage - Health Check Http2

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.computeHealthCheck.ComputeHealthCheck(this, "http2-health-check", {
  check_interval_sec: 1,
  http2_health_check: [
    {
      port: "443",
    },
  ],
  name: "http2-health-check",
  timeout_sec: 1,
});

Example Usage - Health Check Http2 Full

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.computeHealthCheck.ComputeHealthCheck(this, "http2-health-check", {
  check_interval_sec: 1,
  description: "Health check via http2",
  healthy_threshold: 4,
  http2_health_check: [
    {
      host: "1.2.3.4",
      port_name: "health-check-port",
      port_specification: "USE_NAMED_PORT",
      proxy_header: "NONE",
      request_path: "/mypath",
      response: "I AM HEALTHY",
    },
  ],
  name: "http2-health-check",
  timeout_sec: 1,
  unhealthy_threshold: 5,
});

Example Usage - Health Check Grpc

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.computeHealthCheck.ComputeHealthCheck(this, "grpc-health-check", {
  check_interval_sec: 1,
  grpc_health_check: [
    {
      port: "443",
    },
  ],
  name: "grpc-health-check",
  timeout_sec: 1,
});

Example Usage - Health Check Grpc Full

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.computeHealthCheck.ComputeHealthCheck(this, "grpc-health-check", {
  check_interval_sec: 1,
  grpc_health_check: [
    {
      grpc_service_name: "testservice",
      port_name: "health-check-port",
      port_specification: "USE_NAMED_PORT",
    },
  ],
  name: "grpc-health-check",
  timeout_sec: 1,
});

Example Usage - Health Check With Logging

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.computeHealthCheck.ComputeHealthCheck(
  this,
  "health-check-with-logging",
  {
    check_interval_sec: 1,
    log_config: [
      {
        enable: true,
      },
    ],
    name: "tcp-health-check",
    provider: "${google-beta}",
    tcp_health_check: [
      {
        port: "22",
      },
    ],
    timeout_sec: 1,
  }
);

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 [aZ]([AZ09]*[aZ09])? 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.

  • checkIntervalSec - (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.

  • healthyThreshold - (Optional) A so-far unhealthy instance will be marked healthy after this many consecutive successes. The default value is 2.

  • timeoutSec - (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.

  • unhealthyThreshold - (Optional) A so-far healthy instance will be marked unhealthy after this many consecutive failures. The default value is 2.

  • httpHealthCheck - (Optional) A nested object resource Structure is documented below.

  • httpsHealthCheck - (Optional) A nested object resource Structure is documented below.

  • tcpHealthCheck - (Optional) A nested object resource Structure is documented below.

  • sslHealthCheck - (Optional) A nested object resource Structure is documented below.

  • http2HealthCheck - (Optional) A nested object resource Structure is documented below.

  • grpcHealthCheck - (Optional) A nested object resource Structure is documented below.

  • logConfig - (Optional) Configure logging on this health check. Structure is documented below.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

The httpHealthCheck 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.

  • requestPath - (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.

  • portName - (Optional) Port name as defined in InstanceGroup#NamedPort#name. If both port and port_name are defined, port takes precedence.

  • proxyHeader - (Optional) Specifies the type of proxy header to append before sending data to the backend. Default value is none. Possible values are none and proxyV1.

  • portSpecification - (Optional) Specifies how port is selected for health checking, can be one of the following values:

    • useFixedPort: The port number in port is used for health checking.
    • useNamedPort: The portName is used for health checking.
    • useServingPort: 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. Possible values are useFixedPort, useNamedPort, and useServingPort.

The httpsHealthCheck 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.

  • requestPath - (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.

  • portName - (Optional) Port name as defined in InstanceGroup#NamedPort#name. If both port and port_name are defined, port takes precedence.

  • proxyHeader - (Optional) Specifies the type of proxy header to append before sending data to the backend. Default value is none. Possible values are none and proxyV1.

  • portSpecification - (Optional) Specifies how port is selected for health checking, can be one of the following values:

    • useFixedPort: The port number in port is used for health checking.
    • useNamedPort: The portName is used for health checking.
    • useServingPort: 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. Possible values are useFixedPort, useNamedPort, and useServingPort.

The tcpHealthCheck 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 443.

  • portName - (Optional) Port name as defined in InstanceGroup#NamedPort#name. If both port and port_name are defined, port takes precedence.

  • proxyHeader - (Optional) Specifies the type of proxy header to append before sending data to the backend. Default value is none. Possible values are none and proxyV1.

  • portSpecification - (Optional) Specifies how port is selected for health checking, can be one of the following values:

    • useFixedPort: The port number in port is used for health checking.
    • useNamedPort: The portName is used for health checking.
    • useServingPort: 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. Possible values are useFixedPort, useNamedPort, and useServingPort.

The sslHealthCheck 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.

  • portName - (Optional) Port name as defined in InstanceGroup#NamedPort#name. If both port and port_name are defined, port takes precedence.

  • proxyHeader - (Optional) Specifies the type of proxy header to append before sending data to the backend. Default value is none. Possible values are none and proxyV1.

  • portSpecification - (Optional) Specifies how port is selected for health checking, can be one of the following values:

    • useFixedPort: The port number in port is used for health checking.
    • useNamedPort: The portName is used for health checking.
    • useServingPort: 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. Possible values are useFixedPort, useNamedPort, and useServingPort.

The http2HealthCheck 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.

  • requestPath - (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.

  • portName - (Optional) Port name as defined in InstanceGroup#NamedPort#name. If both port and port_name are defined, port takes precedence.

  • proxyHeader - (Optional) Specifies the type of proxy header to append before sending data to the backend. Default value is none. Possible values are none and proxyV1.

  • portSpecification - (Optional) Specifies how port is selected for health checking, can be one of the following values:

    • useFixedPort: The port number in port is used for health checking.
    • useNamedPort: The portName is used for health checking.
    • useServingPort: 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. Possible values are useFixedPort, useNamedPort, and useServingPort.

The grpcHealthCheck block supports:

  • port - (Optional) The port number for the health check request. Must be specified if portName and portSpecification are not set or if port_specification is USE_FIXED_PORT. Valid values are 1 through 65535.

  • portName - (Optional) Port name as defined in InstanceGroup#NamedPort#name. If both port and port_name are defined, port takes precedence.

  • portSpecification - (Optional) Specifies how port is selected for health checking, can be one of the following values:

    • useFixedPort: The port number in port is used for health checking.
    • useNamedPort: The portName is used for health checking.
    • useServingPort: 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, gRPC health check follows behavior specified in port and portName fields. Possible values are useFixedPort, useNamedPort, and useServingPort.
  • grpcServiceName - (Optional) The gRPC service name for the health check. The value of grpcServiceName has the following meanings by convention:

    • Empty serviceName means the overall status of all services at the backend.
    • Non-empty serviceName means the health of that gRPC service, as defined by the owner of the service. The grpcServiceName can only be ASCII.

The logConfig block supports:

  • enable - (Optional) Indicates whether or not to export logs. This is false by default, which means no health check logging will be done.

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

  • id - an identifier for the resource with format projects/{{project}}/global/healthChecks/{{name}}

  • creationTimestamp - Creation timestamp in RFC3339 text format.

  • type - The type of the health check. One of HTTP, HTTPS, TCP, or SSL.

  • selfLink - The URI of the created resource.

Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 20 minutes.
  • update - Default is 20 minutes.
  • delete - Default is 20 minutes.

Import

HealthCheck can be imported using any of these accepted formats:

$ terraform import google_compute_health_check.default projects/{{project}}/global/healthChecks/{{name}}
$ terraform import google_compute_health_check.default {{project}}/{{name}}
$ terraform import google_compute_health_check.default {{name}}

User Project Overrides

This resource supports User Project Overrides.