Configure GCP Regional Health Checks

The gcp:compute/regionHealthCheck:RegionHealthCheck resource, part of the Pulumi GCP provider, defines regional health checks that poll backend instances at specified intervals to determine whether they can receive traffic. This guide focuses on three capabilities: protocol-specific health check configuration (TCP, HTTP, HTTPS, gRPC), threshold tuning, and health check logging.

Health checks monitor instances behind load balancers and mark unresponsive instances as unhealthy to stop routing new connections to them. The examples are intentionally small. Combine them with your own backend services and load balancer configurations.

Check TCP port availability with minimal configuration

Load balancers verify that backend instances accept TCP connections on specific ports without sending application-layer data.

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

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

tcp_region_health_check = gcp.compute.RegionHealthCheck("tcp-region-health-check",
    name="tcp-region-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.NewRegionHealthCheck(ctx, "tcp-region-health-check", &compute.RegionHealthCheckArgs{
			Name:             pulumi.String("tcp-region-health-check"),
			TimeoutSec:       pulumi.Int(1),
			CheckIntervalSec: pulumi.Int(1),
			TcpHealthCheck: &compute.RegionHealthCheckTcpHealthCheckArgs{
				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_region_health_check = new Gcp.Compute.RegionHealthCheck("tcp-region-health-check", new()
    {
        Name = "tcp-region-health-check",
        TimeoutSec = 1,
        CheckIntervalSec = 1,
        TcpHealthCheck = new Gcp.Compute.Inputs.RegionHealthCheckTcpHealthCheckArgs
        {
            Port = 80,
        },
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.RegionHealthCheck;
import com.pulumi.gcp.compute.RegionHealthCheckArgs;
import com.pulumi.gcp.compute.inputs.RegionHealthCheckTcpHealthCheckArgs;
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_region_health_check = new RegionHealthCheck("tcp-region-health-check", RegionHealthCheckArgs.builder()
            .name("tcp-region-health-check")
            .timeoutSec(1)
            .checkIntervalSec(1)
            .tcpHealthCheck(RegionHealthCheckTcpHealthCheckArgs.builder()
                .port(80)
                .build())
            .build());

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

The tcpHealthCheck property configures the port to probe. The timeoutSec and checkIntervalSec properties control how long to wait for a response and how frequently to send probes. Instances that don’t respond within the timeout are marked unhealthy after consecutive failures reach the unhealthyThreshold (defaults to 2).

Probe HTTP endpoints for application health

Web applications expose HTTP endpoints that return status codes indicating readiness to serve traffic.

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

const http_region_health_check = new gcp.compute.RegionHealthCheck("http-region-health-check", {
    name: "http-region-health-check",
    timeoutSec: 1,
    checkIntervalSec: 1,
    httpHealthCheck: {
        port: 80,
    },
});
import pulumi
import pulumi_gcp as gcp

http_region_health_check = gcp.compute.RegionHealthCheck("http-region-health-check",
    name="http-region-health-check",
    timeout_sec=1,
    check_interval_sec=1,
    http_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.NewRegionHealthCheck(ctx, "http-region-health-check", &compute.RegionHealthCheckArgs{
			Name:             pulumi.String("http-region-health-check"),
			TimeoutSec:       pulumi.Int(1),
			CheckIntervalSec: pulumi.Int(1),
			HttpHealthCheck: &compute.RegionHealthCheckHttpHealthCheckArgs{
				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 http_region_health_check = new Gcp.Compute.RegionHealthCheck("http-region-health-check", new()
    {
        Name = "http-region-health-check",
        TimeoutSec = 1,
        CheckIntervalSec = 1,
        HttpHealthCheck = new Gcp.Compute.Inputs.RegionHealthCheckHttpHealthCheckArgs
        {
            Port = 80,
        },
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.RegionHealthCheck;
import com.pulumi.gcp.compute.RegionHealthCheckArgs;
import com.pulumi.gcp.compute.inputs.RegionHealthCheckHttpHealthCheckArgs;
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_region_health_check = new RegionHealthCheck("http-region-health-check", RegionHealthCheckArgs.builder()
            .name("http-region-health-check")
            .timeoutSec(1)
            .checkIntervalSec(1)
            .httpHealthCheck(RegionHealthCheckHttpHealthCheckArgs.builder()
                .port(80)
                .build())
            .build());

    }
}
resources:
  http-region-health-check:
    type: gcp:compute:RegionHealthCheck
    properties:
      name: http-region-health-check
      timeoutSec: 1
      checkIntervalSec: 1
      httpHealthCheck:
        port: '80'

The httpHealthCheck property configures HTTP-based probing. By default, the health check sends GET requests to the root path and expects a 200 response. Instances respond successfully or fail based on HTTP status codes.

Enable health check logging for diagnostics

When troubleshooting backend failures, teams need visibility into which probes succeeded or failed.

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

const http_region_health_check = new gcp.compute.RegionHealthCheck("http-region-health-check", {
    name: "http-region-health-check",
    timeoutSec: 1,
    checkIntervalSec: 1,
    httpHealthCheck: {
        port: 80,
    },
    logConfig: {
        enable: true,
    },
});
import pulumi
import pulumi_gcp as gcp

http_region_health_check = gcp.compute.RegionHealthCheck("http-region-health-check",
    name="http-region-health-check",
    timeout_sec=1,
    check_interval_sec=1,
    http_health_check={
        "port": 80,
    },
    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.NewRegionHealthCheck(ctx, "http-region-health-check", &compute.RegionHealthCheckArgs{
			Name:             pulumi.String("http-region-health-check"),
			TimeoutSec:       pulumi.Int(1),
			CheckIntervalSec: pulumi.Int(1),
			HttpHealthCheck: &compute.RegionHealthCheckHttpHealthCheckArgs{
				Port: pulumi.Int(80),
			},
			LogConfig: &compute.RegionHealthCheckLogConfigArgs{
				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 http_region_health_check = new Gcp.Compute.RegionHealthCheck("http-region-health-check", new()
    {
        Name = "http-region-health-check",
        TimeoutSec = 1,
        CheckIntervalSec = 1,
        HttpHealthCheck = new Gcp.Compute.Inputs.RegionHealthCheckHttpHealthCheckArgs
        {
            Port = 80,
        },
        LogConfig = new Gcp.Compute.Inputs.RegionHealthCheckLogConfigArgs
        {
            Enable = true,
        },
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.RegionHealthCheck;
import com.pulumi.gcp.compute.RegionHealthCheckArgs;
import com.pulumi.gcp.compute.inputs.RegionHealthCheckHttpHealthCheckArgs;
import com.pulumi.gcp.compute.inputs.RegionHealthCheckLogConfigArgs;
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_region_health_check = new RegionHealthCheck("http-region-health-check", RegionHealthCheckArgs.builder()
            .name("http-region-health-check")
            .timeoutSec(1)
            .checkIntervalSec(1)
            .httpHealthCheck(RegionHealthCheckHttpHealthCheckArgs.builder()
                .port(80)
                .build())
            .logConfig(RegionHealthCheckLogConfigArgs.builder()
                .enable(true)
                .build())
            .build());

    }
}
resources:
  http-region-health-check:
    type: gcp:compute:RegionHealthCheck
    properties:
      name: http-region-health-check
      timeoutSec: 1
      checkIntervalSec: 1
      httpHealthCheck:
        port: '80'
      logConfig:
        enable: true

The logConfig property enables health check result logging. Set enable to true to capture probe outcomes in Cloud Logging. This extends the basic HTTP health check with diagnostic capabilities.

Configure HTTP checks with custom paths and thresholds

Production health checks often need custom request paths, host headers, and threshold tuning to match application behavior.

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

const http_region_health_check = new gcp.compute.RegionHealthCheck("http-region-health-check", {
    name: "http-region-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_region_health_check = gcp.compute.RegionHealthCheck("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",
    })
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.NewRegionHealthCheck(ctx, "http-region-health-check", &compute.RegionHealthCheckArgs{
			Name:               pulumi.String("http-region-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.RegionHealthCheckHttpHealthCheckArgs{
				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_region_health_check = new Gcp.Compute.RegionHealthCheck("http-region-health-check", new()
    {
        Name = "http-region-health-check",
        Description = "Health check via http",
        TimeoutSec = 1,
        CheckIntervalSec = 1,
        HealthyThreshold = 4,
        UnhealthyThreshold = 5,
        HttpHealthCheck = new Gcp.Compute.Inputs.RegionHealthCheckHttpHealthCheckArgs
        {
            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.RegionHealthCheck;
import com.pulumi.gcp.compute.RegionHealthCheckArgs;
import com.pulumi.gcp.compute.inputs.RegionHealthCheckHttpHealthCheckArgs;
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_region_health_check = new RegionHealthCheck("http-region-health-check", RegionHealthCheckArgs.builder()
            .name("http-region-health-check")
            .description("Health check via http")
            .timeoutSec(1)
            .checkIntervalSec(1)
            .healthyThreshold(4)
            .unhealthyThreshold(5)
            .httpHealthCheck(RegionHealthCheckHttpHealthCheckArgs.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-region-health-check:
    type: gcp:compute:RegionHealthCheck
    properties:
      name: http-region-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 requestPath property specifies which endpoint to probe (e.g., “/mypath” for a dedicated health endpoint). The host property sets the Host header. The healthyThreshold and unhealthyThreshold properties control how many consecutive successes or failures trigger state changes, preventing flapping when instances experience intermittent issues. The portSpecification property set to “USE_NAMED_PORT” allows referencing ports by name rather than number.

Verify HTTPS endpoints with TLS termination

Applications that terminate TLS at the instance level require health checks that connect over HTTPS.

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

const https_region_health_check = new gcp.compute.RegionHealthCheck("https-region-health-check", {
    name: "https-region-health-check",
    timeoutSec: 1,
    checkIntervalSec: 1,
    httpsHealthCheck: {
        port: 443,
    },
});
import pulumi
import pulumi_gcp as gcp

https_region_health_check = gcp.compute.RegionHealthCheck("https-region-health-check",
    name="https-region-health-check",
    timeout_sec=1,
    check_interval_sec=1,
    https_health_check={
        "port": 443,
    })
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.NewRegionHealthCheck(ctx, "https-region-health-check", &compute.RegionHealthCheckArgs{
			Name:             pulumi.String("https-region-health-check"),
			TimeoutSec:       pulumi.Int(1),
			CheckIntervalSec: pulumi.Int(1),
			HttpsHealthCheck: &compute.RegionHealthCheckHttpsHealthCheckArgs{
				Port: pulumi.Int(443),
			},
		})
		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_region_health_check = new Gcp.Compute.RegionHealthCheck("https-region-health-check", new()
    {
        Name = "https-region-health-check",
        TimeoutSec = 1,
        CheckIntervalSec = 1,
        HttpsHealthCheck = new Gcp.Compute.Inputs.RegionHealthCheckHttpsHealthCheckArgs
        {
            Port = 443,
        },
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.RegionHealthCheck;
import com.pulumi.gcp.compute.RegionHealthCheckArgs;
import com.pulumi.gcp.compute.inputs.RegionHealthCheckHttpsHealthCheckArgs;
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_region_health_check = new RegionHealthCheck("https-region-health-check", RegionHealthCheckArgs.builder()
            .name("https-region-health-check")
            .timeoutSec(1)
            .checkIntervalSec(1)
            .httpsHealthCheck(RegionHealthCheckHttpsHealthCheckArgs.builder()
                .port(443)
                .build())
            .build());

    }
}
resources:
  https-region-health-check:
    type: gcp:compute:RegionHealthCheck
    properties:
      name: https-region-health-check
      timeoutSec: 1
      checkIntervalSec: 1
      httpsHealthCheck:
        port: '443'

The httpsHealthCheck property configures HTTPS-based probing. The health check establishes a TLS connection to the specified port and validates the HTTP response, ensuring both TLS termination and application health.

Check gRPC service health using native protocol

Microservices built on gRPC expose health check endpoints through the gRPC Health Checking Protocol, allowing load balancers to verify service availability without HTTP translation.

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

const grpc_region_health_check = new gcp.compute.RegionHealthCheck("grpc-region-health-check", {
    name: "grpc-region-health-check",
    timeoutSec: 1,
    checkIntervalSec: 1,
    grpcHealthCheck: {
        port: 443,
    },
});
import pulumi
import pulumi_gcp as gcp

grpc_region_health_check = gcp.compute.RegionHealthCheck("grpc-region-health-check",
    name="grpc-region-health-check",
    timeout_sec=1,
    check_interval_sec=1,
    grpc_health_check={
        "port": 443,
    })
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.NewRegionHealthCheck(ctx, "grpc-region-health-check", &compute.RegionHealthCheckArgs{
			Name:             pulumi.String("grpc-region-health-check"),
			TimeoutSec:       pulumi.Int(1),
			CheckIntervalSec: pulumi.Int(1),
			GrpcHealthCheck: &compute.RegionHealthCheckGrpcHealthCheckArgs{
				Port: pulumi.Int(443),
			},
		})
		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_region_health_check = new Gcp.Compute.RegionHealthCheck("grpc-region-health-check", new()
    {
        Name = "grpc-region-health-check",
        TimeoutSec = 1,
        CheckIntervalSec = 1,
        GrpcHealthCheck = new Gcp.Compute.Inputs.RegionHealthCheckGrpcHealthCheckArgs
        {
            Port = 443,
        },
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.RegionHealthCheck;
import com.pulumi.gcp.compute.RegionHealthCheckArgs;
import com.pulumi.gcp.compute.inputs.RegionHealthCheckGrpcHealthCheckArgs;
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_region_health_check = new RegionHealthCheck("grpc-region-health-check", RegionHealthCheckArgs.builder()
            .name("grpc-region-health-check")
            .timeoutSec(1)
            .checkIntervalSec(1)
            .grpcHealthCheck(RegionHealthCheckGrpcHealthCheckArgs.builder()
                .port(443)
                .build())
            .build());

    }
}
resources:
  grpc-region-health-check:
    type: gcp:compute:RegionHealthCheck
    properties:
      name: grpc-region-health-check
      timeoutSec: 1
      checkIntervalSec: 1
      grpcHealthCheck:
        port: '443'

The grpcHealthCheck property configures gRPC-based probing. The health check uses the standard gRPC health checking protocol to query service status, receiving SERVING, NOT_SERVING, or UNKNOWN responses.

Target specific gRPC services by name

When a single gRPC server hosts multiple services, health checks can target a specific service by name.

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

const grpc_region_health_check = new gcp.compute.RegionHealthCheck("grpc-region-health-check", {
    name: "grpc-region-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_region_health_check = gcp.compute.RegionHealthCheck("grpc-region-health-check",
    name="grpc-region-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.NewRegionHealthCheck(ctx, "grpc-region-health-check", &compute.RegionHealthCheckArgs{
			Name:             pulumi.String("grpc-region-health-check"),
			TimeoutSec:       pulumi.Int(1),
			CheckIntervalSec: pulumi.Int(1),
			GrpcHealthCheck: &compute.RegionHealthCheckGrpcHealthCheckArgs{
				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_region_health_check = new Gcp.Compute.RegionHealthCheck("grpc-region-health-check", new()
    {
        Name = "grpc-region-health-check",
        TimeoutSec = 1,
        CheckIntervalSec = 1,
        GrpcHealthCheck = new Gcp.Compute.Inputs.RegionHealthCheckGrpcHealthCheckArgs
        {
            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.RegionHealthCheck;
import com.pulumi.gcp.compute.RegionHealthCheckArgs;
import com.pulumi.gcp.compute.inputs.RegionHealthCheckGrpcHealthCheckArgs;
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_region_health_check = new RegionHealthCheck("grpc-region-health-check", RegionHealthCheckArgs.builder()
            .name("grpc-region-health-check")
            .timeoutSec(1)
            .checkIntervalSec(1)
            .grpcHealthCheck(RegionHealthCheckGrpcHealthCheckArgs.builder()
                .portName("health-check-port")
                .portSpecification("USE_NAMED_PORT")
                .grpcServiceName("testservice")
                .build())
            .build());

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

The grpcServiceName property specifies which service to check within a multi-service deployment. This allows independent health monitoring of individual services running on the same port. The portSpecification property controls whether to use a fixed port number or a named port reference.

Beyond these examples

These snippets focus on specific health check features: protocol-specific health checks (TCP, HTTP, HTTPS, HTTP/2, gRPC), threshold tuning and logging, and named ports and service targeting. They’re intentionally minimal rather than full load balancing configurations.

The examples assume pre-existing infrastructure such as a GCP project and region, backend instances or instance groups to monitor, and load balancer configuration (health checks attach to backend services). 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:

  • Backend service attachment (health checks are referenced by backend services)
  • Proxy headers for client IP preservation
  • Response validation (matching expected response strings)
  • SSL/TLS health checks (separate from HTTPS)

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

Let's configure GCP Regional 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

Protocol Configuration
What health check protocols are available?
You can configure health checks using TCP, SSL, HTTP, HTTPS, HTTP/2, gRPC, or gRPC with TLS. Choose exactly one protocol by setting the corresponding property: tcpHealthCheck, sslHealthCheck, httpHealthCheck, httpsHealthCheck, http2HealthCheck, grpcHealthCheck, or grpcTlsHealthCheck.
How do I configure gRPC health checks?
Use grpcHealthCheck for standard gRPC or grpcTlsHealthCheck for gRPC with TLS. You can optionally specify grpcServiceName to target a specific service.
How do I configure custom health check requests and responses?
For HTTP, HTTPS, HTTP/2, TCP, and SSL checks, use the request and response fields within the protocol-specific configuration. For example, set request: "ARE YOU HEALTHY?" and response: "I AM HEALTHY" in your httpHealthCheck block.
Timing & Intervals
Why am I getting an error about timeout and check interval?
The timeoutSec value must be less than or equal to checkIntervalSec. Setting a timeout longer than the check interval is invalid.
What are the default timing values for health checks?
Both checkIntervalSec and timeoutSec default to 5 seconds. The examples often use 1 second for both to demonstrate more aggressive polling.
Health Thresholds
How do health check thresholds work?
Unhealthy instances become healthy after healthyThreshold consecutive successes (default: 2). Healthy instances become unhealthy after unhealthyThreshold consecutive failures (default: 2).
What happens to unhealthy instances?
Unhealthy instances stop receiving new connections but existing connections continue. The health check keeps polling, and instances can be marked healthy again after consecutive successful probes.
Resource Naming & Immutability
What properties can't I change after creation?
The name, project, and region properties are immutable. Changing any of these requires recreating the resource.
What are the naming requirements for health checks?
Names must be 1-63 characters long, start with a lowercase letter, contain only lowercase letters, digits, or dashes, and cannot end with a dash. This follows RFC1035 naming conventions.
Advanced Features
How do I use named ports instead of fixed port numbers?
Set portSpecification: "USE_NAMED_PORT" and provide portName instead of port in your health check configuration.
How do I enable logging for health checks?
Configure logConfig with enable: true in your health check resource.

Using a different cloud?

Explore networking guides for other cloud providers: