Configure GCP Target HTTP Proxies

The gcp:compute/targetHttpProxy:TargetHttpProxy resource, part of the Pulumi GCP provider, connects global forwarding rules to URL maps, enabling HTTP request routing to backend services or redirect actions. This guide focuses on three capabilities: URL map routing to backend services, connection keep-alive configuration, and HTTP-to-HTTPS redirection.

Target HTTP proxies sit between global forwarding rules (which receive traffic) and URL maps (which define routing logic). The examples are intentionally small. Combine them with your own forwarding rules, backend services, and health checks.

Route HTTP traffic to backend services

Most HTTP load balancers route incoming requests through a URL map to backend services based on host and path rules.

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

const defaultHttpHealthCheck = new gcp.compute.HttpHealthCheck("default", {
    name: "http-health-check",
    requestPath: "/",
    checkIntervalSec: 1,
    timeoutSec: 1,
});
const defaultBackendService = new gcp.compute.BackendService("default", {
    name: "backend-service",
    portName: "http",
    protocol: "HTTP",
    timeoutSec: 10,
    healthChecks: defaultHttpHealthCheck.id,
});
const defaultURLMap = new gcp.compute.URLMap("default", {
    name: "url-map",
    defaultService: defaultBackendService.id,
    hostRules: [{
        hosts: ["mysite.com"],
        pathMatcher: "allpaths",
    }],
    pathMatchers: [{
        name: "allpaths",
        defaultService: defaultBackendService.id,
        pathRules: [{
            paths: ["/*"],
            service: defaultBackendService.id,
        }],
    }],
});
const _default = new gcp.compute.TargetHttpProxy("default", {
    name: "test-proxy",
    urlMap: defaultURLMap.id,
});
import pulumi
import pulumi_gcp as gcp

default_http_health_check = gcp.compute.HttpHealthCheck("default",
    name="http-health-check",
    request_path="/",
    check_interval_sec=1,
    timeout_sec=1)
default_backend_service = gcp.compute.BackendService("default",
    name="backend-service",
    port_name="http",
    protocol="HTTP",
    timeout_sec=10,
    health_checks=default_http_health_check.id)
default_url_map = gcp.compute.URLMap("default",
    name="url-map",
    default_service=default_backend_service.id,
    host_rules=[{
        "hosts": ["mysite.com"],
        "path_matcher": "allpaths",
    }],
    path_matchers=[{
        "name": "allpaths",
        "default_service": default_backend_service.id,
        "path_rules": [{
            "paths": ["/*"],
            "service": default_backend_service.id,
        }],
    }])
default = gcp.compute.TargetHttpProxy("default",
    name="test-proxy",
    url_map=default_url_map.id)
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 {
		defaultHttpHealthCheck, err := compute.NewHttpHealthCheck(ctx, "default", &compute.HttpHealthCheckArgs{
			Name:             pulumi.String("http-health-check"),
			RequestPath:      pulumi.String("/"),
			CheckIntervalSec: pulumi.Int(1),
			TimeoutSec:       pulumi.Int(1),
		})
		if err != nil {
			return err
		}
		defaultBackendService, err := compute.NewBackendService(ctx, "default", &compute.BackendServiceArgs{
			Name:         pulumi.String("backend-service"),
			PortName:     pulumi.String("http"),
			Protocol:     pulumi.String("HTTP"),
			TimeoutSec:   pulumi.Int(10),
			HealthChecks: defaultHttpHealthCheck.ID(),
		})
		if err != nil {
			return err
		}
		defaultURLMap, err := compute.NewURLMap(ctx, "default", &compute.URLMapArgs{
			Name:           pulumi.String("url-map"),
			DefaultService: defaultBackendService.ID(),
			HostRules: compute.URLMapHostRuleArray{
				&compute.URLMapHostRuleArgs{
					Hosts: pulumi.StringArray{
						pulumi.String("mysite.com"),
					},
					PathMatcher: pulumi.String("allpaths"),
				},
			},
			PathMatchers: compute.URLMapPathMatcherArray{
				&compute.URLMapPathMatcherArgs{
					Name:           pulumi.String("allpaths"),
					DefaultService: defaultBackendService.ID(),
					PathRules: compute.URLMapPathMatcherPathRuleArray{
						&compute.URLMapPathMatcherPathRuleArgs{
							Paths: pulumi.StringArray{
								pulumi.String("/*"),
							},
							Service: defaultBackendService.ID(),
						},
					},
				},
			},
		})
		if err != nil {
			return err
		}
		_, err = compute.NewTargetHttpProxy(ctx, "default", &compute.TargetHttpProxyArgs{
			Name:   pulumi.String("test-proxy"),
			UrlMap: defaultURLMap.ID(),
		})
		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 defaultHttpHealthCheck = new Gcp.Compute.HttpHealthCheck("default", new()
    {
        Name = "http-health-check",
        RequestPath = "/",
        CheckIntervalSec = 1,
        TimeoutSec = 1,
    });

    var defaultBackendService = new Gcp.Compute.BackendService("default", new()
    {
        Name = "backend-service",
        PortName = "http",
        Protocol = "HTTP",
        TimeoutSec = 10,
        HealthChecks = defaultHttpHealthCheck.Id,
    });

    var defaultURLMap = new Gcp.Compute.URLMap("default", new()
    {
        Name = "url-map",
        DefaultService = defaultBackendService.Id,
        HostRules = new[]
        {
            new Gcp.Compute.Inputs.URLMapHostRuleArgs
            {
                Hosts = new[]
                {
                    "mysite.com",
                },
                PathMatcher = "allpaths",
            },
        },
        PathMatchers = new[]
        {
            new Gcp.Compute.Inputs.URLMapPathMatcherArgs
            {
                Name = "allpaths",
                DefaultService = defaultBackendService.Id,
                PathRules = new[]
                {
                    new Gcp.Compute.Inputs.URLMapPathMatcherPathRuleArgs
                    {
                        Paths = new[]
                        {
                            "/*",
                        },
                        Service = defaultBackendService.Id,
                    },
                },
            },
        },
    });

    var @default = new Gcp.Compute.TargetHttpProxy("default", new()
    {
        Name = "test-proxy",
        UrlMap = defaultURLMap.Id,
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.HttpHealthCheck;
import com.pulumi.gcp.compute.HttpHealthCheckArgs;
import com.pulumi.gcp.compute.BackendService;
import com.pulumi.gcp.compute.BackendServiceArgs;
import com.pulumi.gcp.compute.URLMap;
import com.pulumi.gcp.compute.URLMapArgs;
import com.pulumi.gcp.compute.inputs.URLMapHostRuleArgs;
import com.pulumi.gcp.compute.inputs.URLMapPathMatcherArgs;
import com.pulumi.gcp.compute.TargetHttpProxy;
import com.pulumi.gcp.compute.TargetHttpProxyArgs;
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 defaultHttpHealthCheck = new HttpHealthCheck("defaultHttpHealthCheck", HttpHealthCheckArgs.builder()
            .name("http-health-check")
            .requestPath("/")
            .checkIntervalSec(1)
            .timeoutSec(1)
            .build());

        var defaultBackendService = new BackendService("defaultBackendService", BackendServiceArgs.builder()
            .name("backend-service")
            .portName("http")
            .protocol("HTTP")
            .timeoutSec(10)
            .healthChecks(defaultHttpHealthCheck.id())
            .build());

        var defaultURLMap = new URLMap("defaultURLMap", URLMapArgs.builder()
            .name("url-map")
            .defaultService(defaultBackendService.id())
            .hostRules(URLMapHostRuleArgs.builder()
                .hosts("mysite.com")
                .pathMatcher("allpaths")
                .build())
            .pathMatchers(URLMapPathMatcherArgs.builder()
                .name("allpaths")
                .defaultService(defaultBackendService.id())
                .pathRules(URLMapPathMatcherPathRuleArgs.builder()
                    .paths("/*")
                    .service(defaultBackendService.id())
                    .build())
                .build())
            .build());

        var default_ = new TargetHttpProxy("default", TargetHttpProxyArgs.builder()
            .name("test-proxy")
            .urlMap(defaultURLMap.id())
            .build());

    }
}
resources:
  default:
    type: gcp:compute:TargetHttpProxy
    properties:
      name: test-proxy
      urlMap: ${defaultURLMap.id}
  defaultURLMap:
    type: gcp:compute:URLMap
    name: default
    properties:
      name: url-map
      defaultService: ${defaultBackendService.id}
      hostRules:
        - hosts:
            - mysite.com
          pathMatcher: allpaths
      pathMatchers:
        - name: allpaths
          defaultService: ${defaultBackendService.id}
          pathRules:
            - paths:
                - /*
              service: ${defaultBackendService.id}
  defaultBackendService:
    type: gcp:compute:BackendService
    name: default
    properties:
      name: backend-service
      portName: http
      protocol: HTTP
      timeoutSec: 10
      healthChecks: ${defaultHttpHealthCheck.id}
  defaultHttpHealthCheck:
    type: gcp:compute:HttpHealthCheck
    name: default
    properties:
      name: http-health-check
      requestPath: /
      checkIntervalSec: 1
      timeoutSec: 1

The urlMap property references a URL map that defines routing logic. The URL map points to backend services, which in turn reference health checks. The target HTTP proxy connects this routing configuration to global forwarding rules (not shown in the example) that receive incoming traffic.

Configure connection keep-alive timeouts

Applications with specific connection reuse requirements can tune how long the proxy keeps idle connections open.

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

const defaultHttpHealthCheck = new gcp.compute.HttpHealthCheck("default", {
    name: "http-health-check",
    requestPath: "/",
    checkIntervalSec: 1,
    timeoutSec: 1,
});
const defaultBackendService = new gcp.compute.BackendService("default", {
    name: "backend-service",
    portName: "http",
    protocol: "HTTP",
    timeoutSec: 10,
    loadBalancingScheme: "EXTERNAL_MANAGED",
    healthChecks: defaultHttpHealthCheck.id,
});
const defaultURLMap = new gcp.compute.URLMap("default", {
    name: "url-map",
    defaultService: defaultBackendService.id,
    hostRules: [{
        hosts: ["mysite.com"],
        pathMatcher: "allpaths",
    }],
    pathMatchers: [{
        name: "allpaths",
        defaultService: defaultBackendService.id,
        pathRules: [{
            paths: ["/*"],
            service: defaultBackendService.id,
        }],
    }],
});
const _default = new gcp.compute.TargetHttpProxy("default", {
    name: "test-http-keep-alive-timeout-proxy",
    httpKeepAliveTimeoutSec: 610,
    urlMap: defaultURLMap.id,
});
import pulumi
import pulumi_gcp as gcp

default_http_health_check = gcp.compute.HttpHealthCheck("default",
    name="http-health-check",
    request_path="/",
    check_interval_sec=1,
    timeout_sec=1)
default_backend_service = gcp.compute.BackendService("default",
    name="backend-service",
    port_name="http",
    protocol="HTTP",
    timeout_sec=10,
    load_balancing_scheme="EXTERNAL_MANAGED",
    health_checks=default_http_health_check.id)
default_url_map = gcp.compute.URLMap("default",
    name="url-map",
    default_service=default_backend_service.id,
    host_rules=[{
        "hosts": ["mysite.com"],
        "path_matcher": "allpaths",
    }],
    path_matchers=[{
        "name": "allpaths",
        "default_service": default_backend_service.id,
        "path_rules": [{
            "paths": ["/*"],
            "service": default_backend_service.id,
        }],
    }])
default = gcp.compute.TargetHttpProxy("default",
    name="test-http-keep-alive-timeout-proxy",
    http_keep_alive_timeout_sec=610,
    url_map=default_url_map.id)
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 {
		defaultHttpHealthCheck, err := compute.NewHttpHealthCheck(ctx, "default", &compute.HttpHealthCheckArgs{
			Name:             pulumi.String("http-health-check"),
			RequestPath:      pulumi.String("/"),
			CheckIntervalSec: pulumi.Int(1),
			TimeoutSec:       pulumi.Int(1),
		})
		if err != nil {
			return err
		}
		defaultBackendService, err := compute.NewBackendService(ctx, "default", &compute.BackendServiceArgs{
			Name:                pulumi.String("backend-service"),
			PortName:            pulumi.String("http"),
			Protocol:            pulumi.String("HTTP"),
			TimeoutSec:          pulumi.Int(10),
			LoadBalancingScheme: pulumi.String("EXTERNAL_MANAGED"),
			HealthChecks:        defaultHttpHealthCheck.ID(),
		})
		if err != nil {
			return err
		}
		defaultURLMap, err := compute.NewURLMap(ctx, "default", &compute.URLMapArgs{
			Name:           pulumi.String("url-map"),
			DefaultService: defaultBackendService.ID(),
			HostRules: compute.URLMapHostRuleArray{
				&compute.URLMapHostRuleArgs{
					Hosts: pulumi.StringArray{
						pulumi.String("mysite.com"),
					},
					PathMatcher: pulumi.String("allpaths"),
				},
			},
			PathMatchers: compute.URLMapPathMatcherArray{
				&compute.URLMapPathMatcherArgs{
					Name:           pulumi.String("allpaths"),
					DefaultService: defaultBackendService.ID(),
					PathRules: compute.URLMapPathMatcherPathRuleArray{
						&compute.URLMapPathMatcherPathRuleArgs{
							Paths: pulumi.StringArray{
								pulumi.String("/*"),
							},
							Service: defaultBackendService.ID(),
						},
					},
				},
			},
		})
		if err != nil {
			return err
		}
		_, err = compute.NewTargetHttpProxy(ctx, "default", &compute.TargetHttpProxyArgs{
			Name:                    pulumi.String("test-http-keep-alive-timeout-proxy"),
			HttpKeepAliveTimeoutSec: pulumi.Int(610),
			UrlMap:                  defaultURLMap.ID(),
		})
		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 defaultHttpHealthCheck = new Gcp.Compute.HttpHealthCheck("default", new()
    {
        Name = "http-health-check",
        RequestPath = "/",
        CheckIntervalSec = 1,
        TimeoutSec = 1,
    });

    var defaultBackendService = new Gcp.Compute.BackendService("default", new()
    {
        Name = "backend-service",
        PortName = "http",
        Protocol = "HTTP",
        TimeoutSec = 10,
        LoadBalancingScheme = "EXTERNAL_MANAGED",
        HealthChecks = defaultHttpHealthCheck.Id,
    });

    var defaultURLMap = new Gcp.Compute.URLMap("default", new()
    {
        Name = "url-map",
        DefaultService = defaultBackendService.Id,
        HostRules = new[]
        {
            new Gcp.Compute.Inputs.URLMapHostRuleArgs
            {
                Hosts = new[]
                {
                    "mysite.com",
                },
                PathMatcher = "allpaths",
            },
        },
        PathMatchers = new[]
        {
            new Gcp.Compute.Inputs.URLMapPathMatcherArgs
            {
                Name = "allpaths",
                DefaultService = defaultBackendService.Id,
                PathRules = new[]
                {
                    new Gcp.Compute.Inputs.URLMapPathMatcherPathRuleArgs
                    {
                        Paths = new[]
                        {
                            "/*",
                        },
                        Service = defaultBackendService.Id,
                    },
                },
            },
        },
    });

    var @default = new Gcp.Compute.TargetHttpProxy("default", new()
    {
        Name = "test-http-keep-alive-timeout-proxy",
        HttpKeepAliveTimeoutSec = 610,
        UrlMap = defaultURLMap.Id,
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.HttpHealthCheck;
import com.pulumi.gcp.compute.HttpHealthCheckArgs;
import com.pulumi.gcp.compute.BackendService;
import com.pulumi.gcp.compute.BackendServiceArgs;
import com.pulumi.gcp.compute.URLMap;
import com.pulumi.gcp.compute.URLMapArgs;
import com.pulumi.gcp.compute.inputs.URLMapHostRuleArgs;
import com.pulumi.gcp.compute.inputs.URLMapPathMatcherArgs;
import com.pulumi.gcp.compute.TargetHttpProxy;
import com.pulumi.gcp.compute.TargetHttpProxyArgs;
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 defaultHttpHealthCheck = new HttpHealthCheck("defaultHttpHealthCheck", HttpHealthCheckArgs.builder()
            .name("http-health-check")
            .requestPath("/")
            .checkIntervalSec(1)
            .timeoutSec(1)
            .build());

        var defaultBackendService = new BackendService("defaultBackendService", BackendServiceArgs.builder()
            .name("backend-service")
            .portName("http")
            .protocol("HTTP")
            .timeoutSec(10)
            .loadBalancingScheme("EXTERNAL_MANAGED")
            .healthChecks(defaultHttpHealthCheck.id())
            .build());

        var defaultURLMap = new URLMap("defaultURLMap", URLMapArgs.builder()
            .name("url-map")
            .defaultService(defaultBackendService.id())
            .hostRules(URLMapHostRuleArgs.builder()
                .hosts("mysite.com")
                .pathMatcher("allpaths")
                .build())
            .pathMatchers(URLMapPathMatcherArgs.builder()
                .name("allpaths")
                .defaultService(defaultBackendService.id())
                .pathRules(URLMapPathMatcherPathRuleArgs.builder()
                    .paths("/*")
                    .service(defaultBackendService.id())
                    .build())
                .build())
            .build());

        var default_ = new TargetHttpProxy("default", TargetHttpProxyArgs.builder()
            .name("test-http-keep-alive-timeout-proxy")
            .httpKeepAliveTimeoutSec(610)
            .urlMap(defaultURLMap.id())
            .build());

    }
}
resources:
  default:
    type: gcp:compute:TargetHttpProxy
    properties:
      name: test-http-keep-alive-timeout-proxy
      httpKeepAliveTimeoutSec: 610
      urlMap: ${defaultURLMap.id}
  defaultURLMap:
    type: gcp:compute:URLMap
    name: default
    properties:
      name: url-map
      defaultService: ${defaultBackendService.id}
      hostRules:
        - hosts:
            - mysite.com
          pathMatcher: allpaths
      pathMatchers:
        - name: allpaths
          defaultService: ${defaultBackendService.id}
          pathRules:
            - paths:
                - /*
              service: ${defaultBackendService.id}
  defaultBackendService:
    type: gcp:compute:BackendService
    name: default
    properties:
      name: backend-service
      portName: http
      protocol: HTTP
      timeoutSec: 10
      loadBalancingScheme: EXTERNAL_MANAGED
      healthChecks: ${defaultHttpHealthCheck.id}
  defaultHttpHealthCheck:
    type: gcp:compute:HttpHealthCheck
    name: default
    properties:
      name: http-health-check
      requestPath: /
      checkIntervalSec: 1
      timeoutSec: 1

The httpKeepAliveTimeoutSec property controls how long connections remain open after completing a response when no new requests arrive. The default is 610 seconds for external load balancers; this example sets it to 610 explicitly. The loadBalancingScheme on the backend service must be EXTERNAL_MANAGED to use this feature.

Redirect HTTP requests to HTTPS

Security policies often require redirecting all HTTP traffic to HTTPS rather than serving content over HTTP.

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

const defaultURLMap = new gcp.compute.URLMap("default", {
    name: "url-map",
    defaultUrlRedirect: {
        httpsRedirect: true,
        stripQuery: false,
    },
});
const _default = new gcp.compute.TargetHttpProxy("default", {
    name: "test-https-redirect-proxy",
    urlMap: defaultURLMap.id,
});
import pulumi
import pulumi_gcp as gcp

default_url_map = gcp.compute.URLMap("default",
    name="url-map",
    default_url_redirect={
        "https_redirect": True,
        "strip_query": False,
    })
default = gcp.compute.TargetHttpProxy("default",
    name="test-https-redirect-proxy",
    url_map=default_url_map.id)
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 {
		defaultURLMap, err := compute.NewURLMap(ctx, "default", &compute.URLMapArgs{
			Name: pulumi.String("url-map"),
			DefaultUrlRedirect: &compute.URLMapDefaultUrlRedirectArgs{
				HttpsRedirect: pulumi.Bool(true),
				StripQuery:    pulumi.Bool(false),
			},
		})
		if err != nil {
			return err
		}
		_, err = compute.NewTargetHttpProxy(ctx, "default", &compute.TargetHttpProxyArgs{
			Name:   pulumi.String("test-https-redirect-proxy"),
			UrlMap: defaultURLMap.ID(),
		})
		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 defaultURLMap = new Gcp.Compute.URLMap("default", new()
    {
        Name = "url-map",
        DefaultUrlRedirect = new Gcp.Compute.Inputs.URLMapDefaultUrlRedirectArgs
        {
            HttpsRedirect = true,
            StripQuery = false,
        },
    });

    var @default = new Gcp.Compute.TargetHttpProxy("default", new()
    {
        Name = "test-https-redirect-proxy",
        UrlMap = defaultURLMap.Id,
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.URLMap;
import com.pulumi.gcp.compute.URLMapArgs;
import com.pulumi.gcp.compute.inputs.URLMapDefaultUrlRedirectArgs;
import com.pulumi.gcp.compute.TargetHttpProxy;
import com.pulumi.gcp.compute.TargetHttpProxyArgs;
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 defaultURLMap = new URLMap("defaultURLMap", URLMapArgs.builder()
            .name("url-map")
            .defaultUrlRedirect(URLMapDefaultUrlRedirectArgs.builder()
                .httpsRedirect(true)
                .stripQuery(false)
                .build())
            .build());

        var default_ = new TargetHttpProxy("default", TargetHttpProxyArgs.builder()
            .name("test-https-redirect-proxy")
            .urlMap(defaultURLMap.id())
            .build());

    }
}
resources:
  default:
    type: gcp:compute:TargetHttpProxy
    properties:
      name: test-https-redirect-proxy
      urlMap: ${defaultURLMap.id}
  defaultURLMap:
    type: gcp:compute:URLMap
    name: default
    properties:
      name: url-map
      defaultUrlRedirect:
        httpsRedirect: true
        stripQuery: false

The URL map’s defaultUrlRedirect property defines a redirect action instead of routing to backend services. Setting httpsRedirect to true causes all HTTP requests to be redirected to their HTTPS equivalents. This configuration assumes an HTTPS listener exists to handle the redirected traffic.

Beyond these examples

These snippets focus on specific target HTTP proxy features: URL map routing and HTTPS redirection, and connection keep-alive tuning. They’re intentionally minimal rather than full load balancer deployments.

The examples assume pre-existing infrastructure such as global forwarding rules (required but not shown in examples), and backend services, health checks, and URL maps. They focus on configuring the proxy rather than provisioning the complete load balancing stack.

To keep things focused, common load balancing patterns are omitted, including:

  • Global forwarding rule configuration (required to receive traffic)
  • SSL certificate management (for HTTPS endpoints)
  • Backend service health checks and load balancing modes
  • URL map path matching and host rules

These omissions are intentional: the goal is to illustrate how the target HTTP proxy is wired, not provide drop-in load balancer modules. See the TargetHttpProxy resource reference for all available configuration options.

Let's configure GCP Target HTTP Proxies

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

Try Pulumi Cloud for FREE

Frequently Asked Questions

Updates & Immutability
Why am I getting a 412 error when updating my TargetHttpProxy?
Updates require an up-to-date fingerprint value. If the fingerprint is stale, the request fails with error 412 conditionNotMet. Retrieve the latest fingerprint with a get() request before updating.
What properties are immutable after creation?
The name, project, proxyBind, description, and httpKeepAliveTimeoutSec properties cannot be changed after creation and require resource recreation. Only urlMap can be updated.
Configuration & Requirements
What are the naming requirements for a TargetHttpProxy?
Names must be 1-63 characters long and match the regex [a-z](?:[-a-z0-9]{0,61}[a-z0-9])?. The first character must be a lowercase letter, followed by lowercase letters, digits, or dashes, and the last character cannot be a dash.
What's required to create a TargetHttpProxy?
You need a name and a urlMap reference that defines the mapping from URLs to backend services.
When do I need to set the proxyBind property?
The proxyBind property only applies when the forwarding rule referencing this proxy has loadBalancingScheme set to INTERNAL_SELF_MANAGED.
Timeouts & Performance
What are the keep-alive timeout limits and defaults?
For global external HTTP(S) load balancers, the default is 610 seconds (min: 5s, max: 1200s). For cross-region internal HTTP(S) load balancers, the default is 600 seconds (min: 5s, max: 600s). This setting is immutable after creation.
Common Use Cases
How do I redirect HTTP traffic to HTTPS?
Configure the urlMap with defaultUrlRedirect setting httpsRedirect to true, as shown in the HTTPS redirect example.

Using a different cloud?

Explore networking guides for other cloud providers: