google_network_services_http_route

HttpRoute is the resource defining how HTTP traffic should be routed by a Mesh or Gateway resource.

To get more information about HttpRoute, see:

Open in Cloud Shell

Example Usage - Network Services Http Route Basic

resource "google_network_services_http_route" "default" {
  provider               = google-beta
  name                   = "my-http-route"
  labels                 = {
    foo = "bar"
  }
  description             = "my description"
  hostnames               = ["example"]
  rules                   {
    matches {
      query_parameters {
        query_parameter = "key"
        exact_match = "value"
      }
      full_path_match = "example"
    }
  }
}
Open in Cloud Shell

Example Usage - Network Services Http Route Matches And Actions

resource "google_network_services_http_route" "default" {
  provider               = google-beta
  name                   = "my-http-route"
  labels                 = {
    foo = "bar"
  }
  description             = "my description"
  hostnames               = ["example"]
  rules                   {
    matches {
      headers {
        header = "header"
        invert_match = false
        regex_match = "header-value"
      }
      query_parameters {
        query_parameter = "key"
        exact_match = "value"
      }
      prefix_match = "example"
      ignore_case = false
    }
    matches {
      headers {
        header = "header"
        invert_match = false
        present_match = true
      }
      query_parameters {
        query_parameter = "key"
        regex_match = "value"
      }
      regex_match = "example"
      ignore_case = false
    }
    matches {
      headers {
        header = "header"
        invert_match = false
        present_match = true
      }
      query_parameters {
        query_parameter = "key"
        present_match = true
      }
      full_path_match = "example"
      ignore_case = false
    }
    action {
      redirect {
        host_redirect = "new-host"
        path_redirect =  "new-path"
        prefix_rewrite =  "new-prefix"
        https_redirect = true
        strip_query = true
        port_redirect = 8081
      }
      url_rewrite {
        path_prefix_rewrite = "new-prefix"
        host_rewrite = "new-host"
      }
      retry_policy {
          retry_conditions = ["server_error"]
          num_retries = 1
          per_try_timeout =  "1s"
      }
      request_mirror_policy {
        destination {
          service_name = "new"
          weight = 1
        }
      }
      cors_policy {
        allow_origins = ["example"]
        allow_methods = ["GET", "PUT"]
        allow_headers = ["version", "type"]
        expose_headers = ["version", "type"]
        max_age = "1s"
        allow_credentials = true
        disabled = false
      }
    }
  }
}
Open in Cloud Shell

Example Usage - Network Services Http Route Actions

resource "google_network_services_http_route" "default" {
  provider               = google-beta
  name                   = "my-http-route"
  labels                 = {
    foo = "bar"
  }
  description             = "my description"
  hostnames               = ["example"]
  rules                   {
    action {
      fault_injection_policy {
       delay {
         fixed_delay = "1s"
         percentage = 1
       }
       abort {
         http_status = 500
         percentage = 1
       }
     }
      url_rewrite {
        path_prefix_rewrite = "new-prefix"
        host_rewrite = "new-host"
      }
      retry_policy {
          retry_conditions = ["server_error"]
          num_retries = 1
          per_try_timeout =  "1s"
      }
      request_mirror_policy {
        destination {
          service_name = "new"
          weight = 1
        }
      }
      cors_policy {
        allow_origins = ["example"]
        allow_methods = ["GET", "PUT"]
        allow_headers = ["version", "type"]
        expose_headers = ["version", "type"]
        max_age = "1s"
        allow_credentials = true
        disabled = false
      }
      request_header_modifier {
        set = { "version": "1", "type" : "json"}
        add = { "minor-version": "1"}
        remove = ["arg"]
      }
      response_header_modifier {
        set = { "version": "1", "type" : "json"}
        add = { "minor-version": "1"}
        remove = ["removearg"]
      }
    }
  }
}
Open in Cloud Shell

Example Usage - Network Services Http Route Mesh Basic

resource "google_network_services_mesh" "default" {
  provider    = google-beta
  name        = "my-http-route"
  labels      = {
    foo = "bar"
  }
  description = "my description"
}

resource "google_network_services_http_route" "default" {
  provider               = google-beta
  name                   = "my-http-route"
  labels                 = {
    foo = "bar"
  }
  description             = "my description"
  hostnames               = ["example"]
  meshes = [
    google_network_services_mesh.default.id
  ]
  rules                   {
    matches {
      query_parameters {
        query_parameter = "key"
        exact_match = "value"
      }
      full_path_match = "example"
    }
  }
}

Argument Reference

The following arguments are supported:

The rules block supports:

The matches block supports:

The query_parameters block supports:

The headers block supports:

The range_match block supports:

The action block supports:

The destinations block supports:

The redirect block supports:

The fault_injection_policy block supports:

The delay block supports:

The abort block supports:

The request_header_modifier block supports:

The response_header_modifier block supports:

The url_rewrite block supports:

The retry_policy block supports:

The request_mirror_policy block supports:

The destination block supports:

The cors_policy 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

HttpRoute can be imported using any of these accepted formats:

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

import {
  id = "projects/{{project}}/locations/global/httpRoutes/{{name}}"
  to = google_network_services_http_route.default
}

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

$ terraform import google_network_services_http_route.default projects/{{project}}/locations/global/httpRoutes/{{name}}
$ terraform import google_network_services_http_route.default {{project}}/{{name}}
$ terraform import google_network_services_http_route.default {{name}}

User Project Overrides

This resource supports User Project Overrides.