google_compute_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.

~>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:

Open in Cloud Shell

Example Usage - Health Check Tcp

resource "google_compute_health_check" "tcp-health-check" {
  name = "tcp-health-check"

  timeout_sec        = 1
  check_interval_sec = 1

  tcp_health_check {
    port = "80"
  }
}
Open in Cloud Shell

Example Usage - Health Check Tcp Full

resource "google_compute_health_check" "tcp-health-check" {
  name        = "tcp-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"
  }
}
Open in Cloud Shell

Example Usage - Health Check Ssl

resource "google_compute_health_check" "ssl-health-check" {
  name = "ssl-health-check"

  timeout_sec        = 1
  check_interval_sec = 1

  ssl_health_check {
    port = "443"
  }
}
Open in Cloud Shell

Example Usage - Health Check Ssl Full

resource "google_compute_health_check" "ssl-health-check" {
  name        = "ssl-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"
  }
}
Open in Cloud Shell

Example Usage - Health Check Http

resource "google_compute_health_check" "http-health-check" {
  name = "http-health-check"

  timeout_sec        = 1
  check_interval_sec = 1

  http_health_check {
    port = 80
  }
}
Open in Cloud Shell

Example Usage - Health Check Http Full

resource "google_compute_health_check" "http-health-check" {
  name        = "http-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"
  }
}
Open in Cloud Shell

Example Usage - Health Check Https

resource "google_compute_health_check" "https-health-check" {
  name = "https-health-check"

  timeout_sec        = 1
  check_interval_sec = 1

  https_health_check {
    port = "443"
  }
}
Open in Cloud Shell

Example Usage - Health Check Https Full

resource "google_compute_health_check" "https-health-check" {
  name        = "https-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"
  }
}
Open in Cloud Shell

Example Usage - Health Check Http2

resource "google_compute_health_check" "http2-health-check" {
  name = "http2-health-check"

  timeout_sec        = 1
  check_interval_sec = 1

  http2_health_check {
    port = "443"
  }
}
Open in Cloud Shell

Example Usage - Health Check Http2 Full

resource "google_compute_health_check" "http2-health-check" {
  name        = "http2-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"
  }
}
Open in Cloud Shell

Example Usage - Health Check Grpc

resource "google_compute_health_check" "grpc-health-check" {
  name = "grpc-health-check"

  timeout_sec        = 1
  check_interval_sec = 1

  grpc_health_check {
    port = "443"
  }
}
Open in Cloud Shell

Example Usage - Health Check Grpc Full

resource "google_compute_health_check" "grpc-health-check" {
  name = "grpc-health-check"

  timeout_sec        = 1
  check_interval_sec = 1

  grpc_health_check {
    port_name          = "health-check-port"
    port_specification = "USE_NAMED_PORT"
    grpc_service_name  = "testservice"
  }
}
Open in Cloud Shell

Example Usage - Health Check With Logging

resource "google_compute_health_check" "health-check-with-logging" {
  provider = google-beta

  name = "tcp-health-check"

  timeout_sec        = 1
  check_interval_sec = 1

  tcp_health_check {
    port = "22"
  }

  log_config {
    enable = true
  }
}

Argument Reference

The following arguments are supported:


The http_health_check block supports:

The https_health_check block supports:

The tcp_health_check block supports:

The ssl_health_check block supports:

The http2_health_check block supports:

The grpc_health_check block supports:

The log_config block supports:

Attributes Reference

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

Timeouts

This resource provides the following Timeouts configuration options:

Import

HealthCheck can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import HealthCheck using one of the formats above. For example:

import {
  id = "projects/{{project}}/global/healthChecks/{{name}}"
  to = google_compute_health_check.default
}

When using the terraform import command, HealthCheck can be imported using one of the formats above. For example:

$ 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.