Configure GCP Compute Health Checks

The gcp:compute/healthCheck:HealthCheck resource, part of the Pulumi GCP provider, defines health checks that poll instances at regular intervals to determine if they can handle traffic. This guide focuses on three capabilities: protocol-specific probe configuration (TCP, HTTP, HTTPS, gRPC), custom request/response validation, and health check logging and regional source constraints.

Health checks monitor backend instances or instance groups and integrate with load balancers to route traffic only to healthy targets. The examples are intentionally small. Combine them with your own backend services and load balancer configurations.

Check TCP port availability with minimal configuration

Most deployments start with a simple TCP probe that verifies instances can accept connections on a specific port.

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const tcp_health_check = new gcp.compute.HealthCheck("tcp-health-check", {
    name: "tcp-health-check",
    timeoutSec: 1,
    checkIntervalSec: 1,
    tcpHealthCheck: {
        port: 80,
    },
});
import pulumi
import pulumi_gcp as gcp

tcp_health_check = gcp.compute.HealthCheck("tcp-health-check",
    name="tcp-health-check",
    timeout_sec=1,
    check_interval_sec=1,
    tcp_health_check={
        "port": 80,
    })
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/compute"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := compute.NewHealthCheck(ctx, "tcp-health-check", &compute.HealthCheckArgs{
			Name:             pulumi.String("tcp-health-check"),
			TimeoutSec:       pulumi.Int(1),
			CheckIntervalSec: pulumi.Int(1),
			TcpHealthCheck: &compute.HealthCheckTcpHealthCheckArgs{
				Port: pulumi.Int(80),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() => 
{
    var tcp_health_check = new Gcp.Compute.HealthCheck("tcp-health-check", new()
    {
        Name = "tcp-health-check",
        TimeoutSec = 1,
        CheckIntervalSec = 1,
        TcpHealthCheck = new Gcp.Compute.Inputs.HealthCheckTcpHealthCheckArgs
        {
            Port = 80,
        },
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.HealthCheck;
import com.pulumi.gcp.compute.HealthCheckArgs;
import com.pulumi.gcp.compute.inputs.HealthCheckTcpHealthCheckArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var tcp_health_check = new HealthCheck("tcp-health-check", HealthCheckArgs.builder()
            .name("tcp-health-check")
            .timeoutSec(1)
            .checkIntervalSec(1)
            .tcpHealthCheck(HealthCheckTcpHealthCheckArgs.builder()
                .port(80)
                .build())
            .build());

    }
}
resources:
  tcp-health-check:
    type: gcp:compute:HealthCheck
    properties:
      name: tcp-health-check
      timeoutSec: 1
      checkIntervalSec: 1
      tcpHealthCheck:
        port: '80'

The tcpHealthCheck block configures a TCP connection attempt to the specified port. The timeoutSec and checkIntervalSec properties control how long to wait for a response and how frequently to probe. Instances that fail to respond within the timeout are marked unhealthy after consecutive failures.

Probe HTTP endpoints with custom paths and responses

Applications often expose dedicated health endpoints that return specific responses, allowing health checks to verify both connectivity and application readiness.

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const http_health_check = new gcp.compute.HealthCheck("http-health-check", {
    name: "http-health-check",
    description: "Health check via http",
    timeoutSec: 1,
    checkIntervalSec: 1,
    healthyThreshold: 4,
    unhealthyThreshold: 5,
    httpHealthCheck: {
        portName: "health-check-port",
        portSpecification: "USE_NAMED_PORT",
        host: "1.2.3.4",
        requestPath: "/mypath",
        proxyHeader: "NONE",
        response: "I AM HEALTHY",
    },
});
import pulumi
import pulumi_gcp as gcp

http_health_check = gcp.compute.HealthCheck("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",
    })
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/compute"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := compute.NewHealthCheck(ctx, "http-health-check", &compute.HealthCheckArgs{
			Name:               pulumi.String("http-health-check"),
			Description:        pulumi.String("Health check via http"),
			TimeoutSec:         pulumi.Int(1),
			CheckIntervalSec:   pulumi.Int(1),
			HealthyThreshold:   pulumi.Int(4),
			UnhealthyThreshold: pulumi.Int(5),
			HttpHealthCheck: &compute.HealthCheckHttpHealthCheckArgs{
				PortName:          pulumi.String("health-check-port"),
				PortSpecification: pulumi.String("USE_NAMED_PORT"),
				Host:              pulumi.String("1.2.3.4"),
				RequestPath:       pulumi.String("/mypath"),
				ProxyHeader:       pulumi.String("NONE"),
				Response:          pulumi.String("I AM HEALTHY"),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() => 
{
    var http_health_check = new Gcp.Compute.HealthCheck("http-health-check", new()
    {
        Name = "http-health-check",
        Description = "Health check via http",
        TimeoutSec = 1,
        CheckIntervalSec = 1,
        HealthyThreshold = 4,
        UnhealthyThreshold = 5,
        HttpHealthCheck = new Gcp.Compute.Inputs.HealthCheckHttpHealthCheckArgs
        {
            PortName = "health-check-port",
            PortSpecification = "USE_NAMED_PORT",
            Host = "1.2.3.4",
            RequestPath = "/mypath",
            ProxyHeader = "NONE",
            Response = "I AM HEALTHY",
        },
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.HealthCheck;
import com.pulumi.gcp.compute.HealthCheckArgs;
import com.pulumi.gcp.compute.inputs.HealthCheckHttpHealthCheckArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var http_health_check = new HealthCheck("http-health-check", HealthCheckArgs.builder()
            .name("http-health-check")
            .description("Health check via http")
            .timeoutSec(1)
            .checkIntervalSec(1)
            .healthyThreshold(4)
            .unhealthyThreshold(5)
            .httpHealthCheck(HealthCheckHttpHealthCheckArgs.builder()
                .portName("health-check-port")
                .portSpecification("USE_NAMED_PORT")
                .host("1.2.3.4")
                .requestPath("/mypath")
                .proxyHeader("NONE")
                .response("I AM HEALTHY")
                .build())
            .build());

    }
}
resources:
  http-health-check:
    type: gcp:compute:HealthCheck
    properties:
      name: http-health-check
      description: Health check via http
      timeoutSec: 1
      checkIntervalSec: 1
      healthyThreshold: 4
      unhealthyThreshold: 5
      httpHealthCheck:
        portName: health-check-port
        portSpecification: USE_NAMED_PORT
        host: 1.2.3.4
        requestPath: /mypath
        proxyHeader: NONE
        response: I AM HEALTHY

The httpHealthCheck block sends HTTP GET requests to the specified requestPath and validates the response body against the expected response string. The portSpecification set to USE_NAMED_PORT allows the health check to target a named port defined on the instance group. The healthyThreshold and unhealthyThreshold properties control how many consecutive successes or failures trigger state transitions.

Validate HTTPS endpoints with SSL termination

Production services typically require encrypted health checks to match their HTTPS endpoints, ensuring probes follow the same security posture as client traffic.

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const https_health_check = new gcp.compute.HealthCheck("https-health-check", {
    name: "https-health-check",
    description: "Health check via https",
    timeoutSec: 1,
    checkIntervalSec: 1,
    healthyThreshold: 4,
    unhealthyThreshold: 5,
    httpsHealthCheck: {
        portName: "health-check-port",
        portSpecification: "USE_NAMED_PORT",
        host: "1.2.3.4",
        requestPath: "/mypath",
        proxyHeader: "NONE",
        response: "I AM HEALTHY",
    },
});
import pulumi
import pulumi_gcp as gcp

https_health_check = gcp.compute.HealthCheck("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",
    })
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/compute"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := compute.NewHealthCheck(ctx, "https-health-check", &compute.HealthCheckArgs{
			Name:               pulumi.String("https-health-check"),
			Description:        pulumi.String("Health check via https"),
			TimeoutSec:         pulumi.Int(1),
			CheckIntervalSec:   pulumi.Int(1),
			HealthyThreshold:   pulumi.Int(4),
			UnhealthyThreshold: pulumi.Int(5),
			HttpsHealthCheck: &compute.HealthCheckHttpsHealthCheckArgs{
				PortName:          pulumi.String("health-check-port"),
				PortSpecification: pulumi.String("USE_NAMED_PORT"),
				Host:              pulumi.String("1.2.3.4"),
				RequestPath:       pulumi.String("/mypath"),
				ProxyHeader:       pulumi.String("NONE"),
				Response:          pulumi.String("I AM HEALTHY"),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() => 
{
    var https_health_check = new Gcp.Compute.HealthCheck("https-health-check", new()
    {
        Name = "https-health-check",
        Description = "Health check via https",
        TimeoutSec = 1,
        CheckIntervalSec = 1,
        HealthyThreshold = 4,
        UnhealthyThreshold = 5,
        HttpsHealthCheck = new Gcp.Compute.Inputs.HealthCheckHttpsHealthCheckArgs
        {
            PortName = "health-check-port",
            PortSpecification = "USE_NAMED_PORT",
            Host = "1.2.3.4",
            RequestPath = "/mypath",
            ProxyHeader = "NONE",
            Response = "I AM HEALTHY",
        },
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.HealthCheck;
import com.pulumi.gcp.compute.HealthCheckArgs;
import com.pulumi.gcp.compute.inputs.HealthCheckHttpsHealthCheckArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var https_health_check = new HealthCheck("https-health-check", HealthCheckArgs.builder()
            .name("https-health-check")
            .description("Health check via https")
            .timeoutSec(1)
            .checkIntervalSec(1)
            .healthyThreshold(4)
            .unhealthyThreshold(5)
            .httpsHealthCheck(HealthCheckHttpsHealthCheckArgs.builder()
                .portName("health-check-port")
                .portSpecification("USE_NAMED_PORT")
                .host("1.2.3.4")
                .requestPath("/mypath")
                .proxyHeader("NONE")
                .response("I AM HEALTHY")
                .build())
            .build());

    }
}
resources:
  https-health-check:
    type: gcp:compute:HealthCheck
    properties:
      name: https-health-check
      description: Health check via https
      timeoutSec: 1
      checkIntervalSec: 1
      healthyThreshold: 4
      unhealthyThreshold: 5
      httpsHealthCheck:
        portName: health-check-port
        portSpecification: USE_NAMED_PORT
        host: 1.2.3.4
        requestPath: /mypath
        proxyHeader: NONE
        response: I AM HEALTHY

The httpsHealthCheck block performs TLS-encrypted probes to the specified port and path. The host property sets the Host header in the request, allowing health checks to target virtual hosts or validate SNI behavior.

Monitor gRPC services with named ports

gRPC services require protocol-specific health checks that can invoke the gRPC health checking protocol rather than simple TCP or HTTP probes.

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const grpc_health_check = new gcp.compute.HealthCheck("grpc-health-check", {
    name: "grpc-health-check",
    timeoutSec: 1,
    checkIntervalSec: 1,
    grpcHealthCheck: {
        portName: "health-check-port",
        portSpecification: "USE_NAMED_PORT",
        grpcServiceName: "testservice",
    },
});
import pulumi
import pulumi_gcp as gcp

grpc_health_check = gcp.compute.HealthCheck("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",
    })
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/compute"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := compute.NewHealthCheck(ctx, "grpc-health-check", &compute.HealthCheckArgs{
			Name:             pulumi.String("grpc-health-check"),
			TimeoutSec:       pulumi.Int(1),
			CheckIntervalSec: pulumi.Int(1),
			GrpcHealthCheck: &compute.HealthCheckGrpcHealthCheckArgs{
				PortName:          pulumi.String("health-check-port"),
				PortSpecification: pulumi.String("USE_NAMED_PORT"),
				GrpcServiceName:   pulumi.String("testservice"),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() => 
{
    var grpc_health_check = new Gcp.Compute.HealthCheck("grpc-health-check", new()
    {
        Name = "grpc-health-check",
        TimeoutSec = 1,
        CheckIntervalSec = 1,
        GrpcHealthCheck = new Gcp.Compute.Inputs.HealthCheckGrpcHealthCheckArgs
        {
            PortName = "health-check-port",
            PortSpecification = "USE_NAMED_PORT",
            GrpcServiceName = "testservice",
        },
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.HealthCheck;
import com.pulumi.gcp.compute.HealthCheckArgs;
import com.pulumi.gcp.compute.inputs.HealthCheckGrpcHealthCheckArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var grpc_health_check = new HealthCheck("grpc-health-check", HealthCheckArgs.builder()
            .name("grpc-health-check")
            .timeoutSec(1)
            .checkIntervalSec(1)
            .grpcHealthCheck(HealthCheckGrpcHealthCheckArgs.builder()
                .portName("health-check-port")
                .portSpecification("USE_NAMED_PORT")
                .grpcServiceName("testservice")
                .build())
            .build());

    }
}
resources:
  grpc-health-check:
    type: gcp:compute:HealthCheck
    properties:
      name: grpc-health-check
      timeoutSec: 1
      checkIntervalSec: 1
      grpcHealthCheck:
        portName: health-check-port
        portSpecification: USE_NAMED_PORT
        grpcServiceName: testservice

The grpcHealthCheck block uses the gRPC health checking protocol to query the specified grpcServiceName. The portSpecification set to USE_NAMED_PORT allows targeting a named port on the instance group, which is common for gRPC services that may run on non-standard ports.

Enable health check logging for diagnostics

When troubleshooting instance health or investigating unexpected traffic patterns, health check logs provide visibility into probe results and timing.

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const health_check_with_logging = new gcp.compute.HealthCheck("health-check-with-logging", {
    name: "tcp-health-check",
    timeoutSec: 1,
    checkIntervalSec: 1,
    tcpHealthCheck: {
        port: 22,
    },
    logConfig: {
        enable: true,
    },
});
import pulumi
import pulumi_gcp as gcp

health_check_with_logging = gcp.compute.HealthCheck("health-check-with-logging",
    name="tcp-health-check",
    timeout_sec=1,
    check_interval_sec=1,
    tcp_health_check={
        "port": 22,
    },
    log_config={
        "enable": True,
    })
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/compute"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := compute.NewHealthCheck(ctx, "health-check-with-logging", &compute.HealthCheckArgs{
			Name:             pulumi.String("tcp-health-check"),
			TimeoutSec:       pulumi.Int(1),
			CheckIntervalSec: pulumi.Int(1),
			TcpHealthCheck: &compute.HealthCheckTcpHealthCheckArgs{
				Port: pulumi.Int(22),
			},
			LogConfig: &compute.HealthCheckLogConfigArgs{
				Enable: pulumi.Bool(true),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() => 
{
    var health_check_with_logging = new Gcp.Compute.HealthCheck("health-check-with-logging", new()
    {
        Name = "tcp-health-check",
        TimeoutSec = 1,
        CheckIntervalSec = 1,
        TcpHealthCheck = new Gcp.Compute.Inputs.HealthCheckTcpHealthCheckArgs
        {
            Port = 22,
        },
        LogConfig = new Gcp.Compute.Inputs.HealthCheckLogConfigArgs
        {
            Enable = true,
        },
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.HealthCheck;
import com.pulumi.gcp.compute.HealthCheckArgs;
import com.pulumi.gcp.compute.inputs.HealthCheckTcpHealthCheckArgs;
import com.pulumi.gcp.compute.inputs.HealthCheckLogConfigArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var health_check_with_logging = new HealthCheck("health-check-with-logging", HealthCheckArgs.builder()
            .name("tcp-health-check")
            .timeoutSec(1)
            .checkIntervalSec(1)
            .tcpHealthCheck(HealthCheckTcpHealthCheckArgs.builder()
                .port(22)
                .build())
            .logConfig(HealthCheckLogConfigArgs.builder()
                .enable(true)
                .build())
            .build());

    }
}
resources:
  health-check-with-logging:
    type: gcp:compute:HealthCheck
    properties:
      name: tcp-health-check
      timeoutSec: 1
      checkIntervalSec: 1
      tcpHealthCheck:
        port: '22'
      logConfig:
        enable: true

The logConfig block with enable set to true sends health check probe results to Cloud Logging. This captures each probe attempt, its result (success or failure), and timing information, which helps diagnose why instances are marked unhealthy or identify network issues.

Restrict health check probes to specific regions

Global load balancers can constrain health check traffic to specific regions, reducing cross-region bandwidth costs or meeting data residency requirements.

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const http_health_check_with_source_regions = new gcp.compute.HealthCheck("http-health-check-with-source-regions", {
    name: "http-health-check",
    checkIntervalSec: 30,
    httpHealthCheck: {
        port: 80,
        portSpecification: "USE_FIXED_PORT",
    },
    sourceRegions: [
        "us-west1",
        "us-central1",
        "us-east5",
    ],
});
import pulumi
import pulumi_gcp as gcp

http_health_check_with_source_regions = gcp.compute.HealthCheck("http-health-check-with-source-regions",
    name="http-health-check",
    check_interval_sec=30,
    http_health_check={
        "port": 80,
        "port_specification": "USE_FIXED_PORT",
    },
    source_regions=[
        "us-west1",
        "us-central1",
        "us-east5",
    ])
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/compute"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := compute.NewHealthCheck(ctx, "http-health-check-with-source-regions", &compute.HealthCheckArgs{
			Name:             pulumi.String("http-health-check"),
			CheckIntervalSec: pulumi.Int(30),
			HttpHealthCheck: &compute.HealthCheckHttpHealthCheckArgs{
				Port:              pulumi.Int(80),
				PortSpecification: pulumi.String("USE_FIXED_PORT"),
			},
			SourceRegions: pulumi.StringArray{
				pulumi.String("us-west1"),
				pulumi.String("us-central1"),
				pulumi.String("us-east5"),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() => 
{
    var http_health_check_with_source_regions = new Gcp.Compute.HealthCheck("http-health-check-with-source-regions", new()
    {
        Name = "http-health-check",
        CheckIntervalSec = 30,
        HttpHealthCheck = new Gcp.Compute.Inputs.HealthCheckHttpHealthCheckArgs
        {
            Port = 80,
            PortSpecification = "USE_FIXED_PORT",
        },
        SourceRegions = new[]
        {
            "us-west1",
            "us-central1",
            "us-east5",
        },
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.HealthCheck;
import com.pulumi.gcp.compute.HealthCheckArgs;
import com.pulumi.gcp.compute.inputs.HealthCheckHttpHealthCheckArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var http_health_check_with_source_regions = new HealthCheck("http-health-check-with-source-regions", HealthCheckArgs.builder()
            .name("http-health-check")
            .checkIntervalSec(30)
            .httpHealthCheck(HealthCheckHttpHealthCheckArgs.builder()
                .port(80)
                .portSpecification("USE_FIXED_PORT")
                .build())
            .sourceRegions(            
                "us-west1",
                "us-central1",
                "us-east5")
            .build());

    }
}
resources:
  http-health-check-with-source-regions:
    type: gcp:compute:HealthCheck
    properties:
      name: http-health-check
      checkIntervalSec: 30
      httpHealthCheck:
        port: 80
        portSpecification: USE_FIXED_PORT
      sourceRegions:
        - us-west1
        - us-central1
        - us-east5

The sourceRegions property limits health check probes to exactly three specified regions. This configuration requires checkIntervalSec to be at least 30 seconds and disables several features: SSL, HTTP2, and GRPC protocols are not supported, the TCP request field cannot be used, and the proxyHeader field for HTTP/HTTPS/TCP is unavailable. Health checks with sourceRegions cannot be used with BackendService or managed instance group auto-healing.

Beyond these examples

These snippets focus on specific health check features: protocol-specific probes (TCP, HTTP, HTTPS, gRPC), custom request/response validation, and health check logging and regional constraints. They’re intentionally minimal rather than full load balancing configurations.

The examples assume pre-existing infrastructure such as a GCP project with Compute Engine API enabled and backend instances or instance groups to monitor. They focus on configuring the health check rather than provisioning the complete load balancing stack.

To keep things focused, common health check patterns are omitted, including:

  • Integration with load balancers (BackendService)
  • Managed instance group auto-healing configuration
  • Proxy header configuration for HTTP/HTTPS checks
  • Advanced threshold tuning (healthyThreshold, unhealthyThreshold)

These omissions are intentional: the goal is to illustrate how each health check feature is wired, not provide drop-in load balancing modules. See the Compute HealthCheck resource reference for all available configuration options.

Let's configure GCP Compute Health Checks

Get started with Pulumi Cloud, then follow our quick setup guide to deploy this infrastructure.

Try Pulumi Cloud for FREE

Frequently Asked Questions

Health Check Types & Selection
When should I use legacy HTTP(S) health checks instead of the modern health check resource?
Legacy HTTP(S) health checks must be used for target pool-based network load balancers. Modern health checks are incompatible with this configuration.
What health check protocols are supported?
Seven protocols are supported: TCP, SSL, HTTP, HTTPS, HTTP2, GRPC, and GRPC with TLS. Each protocol is configured using its respective health check block (tcpHealthCheck, sslHealthCheck, httpHealthCheck, httpsHealthCheck, http2HealthCheck, grpcHealthCheck, or grpcTlsHealthCheck).
Timing & Thresholds
What are the default timing and threshold values for health checks?
Health checks default to 5-second intervals (checkIntervalSec) and 5-second timeouts (timeoutSec). Instances are marked healthy after 2 consecutive successes (healthyThreshold) and unhealthy after 2 consecutive failures (unhealthyThreshold).
Why am I getting an error about timeoutSec and checkIntervalSec?
The timeoutSec value cannot be greater than checkIntervalSec. Ensure your timeout is less than or equal to your check interval.
How often should I configure health checks to run?
The default 5-second interval (checkIntervalSec) works for most cases. If using sourceRegions, you must set checkIntervalSec to at least 30 seconds.
Source Regions & Restrictions
What are the restrictions when using sourceRegions?
When configuring sourceRegions, you must specify exactly 3 regions. This configuration has several restrictions: SSL, HTTP2, and GRPC protocols are not supported; the TCP request field is not supported; the proxyHeader field for HTTP, HTTPS, and TCP is not supported; checkIntervalSec must be at least 30 seconds; and the health check cannot be used with BackendService or managed instance group auto-healing.
Can I use source regions with GRPC health checks?
No, GRPC and HTTP2 protocols are not supported when sourceRegions is configured. Use TCP, HTTP, or HTTPS instead.
Configuration & Naming
Can I rename a health check after creation?
No, the name property is immutable and cannot be changed after the health check is created.
What are the naming requirements for health checks?
Names must be 1-63 characters long, start with a lowercase letter, and contain only lowercase letters, digits, and dashes. The name cannot end with a dash.
What's the difference between using port and portName?
Use port to specify a fixed port number (e.g., 80, 443). Use portName with portSpecification set to USE_NAMED_PORT to reference a named port defined on your backend instances.
How do I enable logging for my health checks?
Configure the logConfig block with enable set to true to enable health check logging.

Using a different cloud?

Explore networking guides for other cloud providers: