google_compute_target_http_proxy

Represents a TargetHttpProxy resource, which is used by one or more global forwarding rule to route incoming HTTP requests to a URL map.

To get more information about TargetHttpProxy, see:

Open in Cloud Shell

Example Usage - Target Http Proxy Basic

resource "google_compute_target_http_proxy" "default" {
  name    = "test-proxy"
  url_map = google_compute_url_map.default.id
}

resource "google_compute_url_map" "default" {
  name            = "url-map"
  default_service = google_compute_backend_service.default.id

  host_rule {
    hosts        = ["mysite.com"]
    path_matcher = "allpaths"
  }

  path_matcher {
    name            = "allpaths"
    default_service = google_compute_backend_service.default.id

    path_rule {
      paths   = ["/*"]
      service = google_compute_backend_service.default.id
    }
  }
}

resource "google_compute_backend_service" "default" {
  name        = "backend-service"
  port_name   = "http"
  protocol    = "HTTP"
  timeout_sec = 10

  health_checks = [google_compute_http_health_check.default.id]
}

resource "google_compute_http_health_check" "default" {
  name               = "http-health-check"
  request_path       = "/"
  check_interval_sec = 1
  timeout_sec        = 1
}
Open in Cloud Shell

Example Usage - Target Http Proxy Http Keep Alive Timeout

resource "google_compute_target_http_proxy" "default" {
  name                        = "test-http-keep-alive-timeout-proxy"
  http_keep_alive_timeout_sec = 610
  url_map                     = google_compute_url_map.default.id
}

resource "google_compute_url_map" "default" {
  name            = "url-map"
  default_service = google_compute_backend_service.default.id

  host_rule {
    hosts        = ["mysite.com"]
    path_matcher = "allpaths"
  }

  path_matcher {
    name            = "allpaths"
    default_service = google_compute_backend_service.default.id

    path_rule {
      paths   = ["/*"]
      service = google_compute_backend_service.default.id
    }
  }
}

resource "google_compute_backend_service" "default" {
  name                  = "backend-service"
  port_name             = "http"
  protocol              = "HTTP"
  timeout_sec           = 10
  load_balancing_scheme = "EXTERNAL_MANAGED"

  health_checks = [google_compute_http_health_check.default.id]
}

resource "google_compute_http_health_check" "default" {
  name               = "http-health-check"
  request_path       = "/"
  check_interval_sec = 1
  timeout_sec        = 1
}
Open in Cloud Shell

Example Usage - Target Http Proxy Https Redirect

resource "google_compute_target_http_proxy" "default" {
  name    = "test-https-redirect-proxy"
  url_map = google_compute_url_map.default.id
}

resource "google_compute_url_map" "default" {
  name            = "url-map"
  default_url_redirect {
    https_redirect = true
    strip_query    = false
  }
}

Argument Reference

The following arguments are supported:


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

TargetHttpProxy can be imported using any of these accepted formats:

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

import {
  id = "projects/{{project}}/global/targetHttpProxies/{{name}}"
  to = google_compute_target_http_proxy.default
}

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

$ terraform import google_compute_target_http_proxy.default projects/{{project}}/global/targetHttpProxies/{{name}}
$ terraform import google_compute_target_http_proxy.default {{project}}/{{name}}
$ terraform import google_compute_target_http_proxy.default {{name}}

User Project Overrides

This resource supports User Project Overrides.