| --- |
| # ---------------------------------------------------------------------------- |
| # |
| # *** AUTO GENERATED CODE *** Type: MMv1 *** |
| # |
| # ---------------------------------------------------------------------------- |
| # |
| # This file is automatically generated by Magic Modules and manual |
| # changes will be clobbered when the file is regenerated. |
| # |
| # Please read more about how to change this file in |
| # .github/CONTRIBUTING.md. |
| # |
| # ---------------------------------------------------------------------------- |
| subcategory: "Network services" |
| description: |- |
| HttpRoute is the resource defining how HTTP traffic should be routed by a Mesh or Gateway resource. |
| --- |
| |
| # google\_network\_services\_http\_route |
| |
| HttpRoute is the resource defining how HTTP traffic should be routed by a Mesh or Gateway resource. |
| |
| ~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider. |
| See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources. |
| |
| To get more information about HttpRoute, see: |
| |
| * [API documentation](https://cloud.google.com/traffic-director/docs/reference/network-services/rest/v1beta1/projects.locations.httpRoutes) |
| * How-to Guides |
| * [Setup HTTP Services](https://cloud.google.com/traffic-director/docs/set-up-envoy-http-mesh) |
| |
| <div class = "oics-button" style="float: right; margin: 0 0 -15px"> |
| <a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=network_services_http_route_basic&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank"> |
| <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;"> |
| </a> |
| </div> |
| ## Example Usage - Network Services Http Route Basic |
| |
| |
| ```hcl |
| 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" |
| } |
| } |
| } |
| ``` |
| <div class = "oics-button" style="float: right; margin: 0 0 -15px"> |
| <a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=network_services_http_route_matches_and_actions&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank"> |
| <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;"> |
| </a> |
| </div> |
| ## Example Usage - Network Services Http Route Matches And Actions |
| |
| |
| ```hcl |
| 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 |
| } |
| } |
| } |
| } |
| ``` |
| <div class = "oics-button" style="float: right; margin: 0 0 -15px"> |
| <a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=network_services_http_route_actions&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank"> |
| <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;"> |
| </a> |
| </div> |
| ## Example Usage - Network Services Http Route Actions |
| |
| |
| ```hcl |
| 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"] |
| } |
| } |
| } |
| } |
| ``` |
| <div class = "oics-button" style="float: right; margin: 0 0 -15px"> |
| <a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=network_services_http_route_mesh_basic&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank"> |
| <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;"> |
| </a> |
| </div> |
| ## Example Usage - Network Services Http Route Mesh Basic |
| |
| |
| ```hcl |
| 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: |
| |
| |
| * `hostnames` - |
| (Required) |
| Set of hosts that should match against the HTTP host header to select a HttpRoute to process the request. |
| |
| * `rules` - |
| (Required) |
| Rules that define how traffic is routed and handled. |
| Structure is [documented below](#nested_rules). |
| |
| * `name` - |
| (Required) |
| Name of the HttpRoute resource. |
| |
| |
| <a name="nested_rules"></a>The `rules` block supports: |
| |
| * `matches` - |
| (Optional) |
| A list of matches define conditions used for matching the rule against incoming HTTP requests. Each match is independent, i.e. this rule will be matched if ANY one of the matches is satisfied. |
| If no matches field is specified, this rule will unconditionally match traffic. |
| If a default rule is desired to be configured, add a rule with no matches specified to the end of the rules list. |
| Structure is [documented below](#nested_matches). |
| |
| * `action` - |
| (Optional) |
| The detailed rule defining how to route matched traffic. |
| Structure is [documented below](#nested_action). |
| |
| |
| <a name="nested_matches"></a>The `matches` block supports: |
| |
| * `ignore_case` - |
| (Optional) |
| Specifies if prefixMatch and fullPathMatch matches are case sensitive. The default value is false. |
| |
| * `full_path_match` - |
| (Optional) |
| The HTTP request path value should exactly match this value. |
| |
| * `prefix_match` - |
| (Optional) |
| The HTTP request path value must begin with specified prefixMatch. prefixMatch must begin with a /. |
| |
| * `regex_match` - |
| (Optional) |
| The HTTP request path value must satisfy the regular expression specified by regexMatch after removing any query parameters and anchor supplied with the original URL. For regular expression grammar, please see https://github.com/google/re2/wiki/Syntax |
| |
| * `query_parameters` - |
| (Optional) |
| Specifies a list of query parameters to match against. |
| Structure is [documented below](#nested_query_parameters). |
| |
| * `headers` - |
| (Optional) |
| Specifies a list of HTTP request headers to match against. |
| Structure is [documented below](#nested_headers). |
| |
| |
| <a name="nested_query_parameters"></a>The `query_parameters` block supports: |
| |
| * `query_parameter` - |
| (Optional) |
| The name of the query parameter to match. |
| |
| * `exact_match` - |
| (Optional) |
| The value of the query parameter must exactly match the contents of exactMatch. |
| |
| * `regex_match` - |
| (Optional) |
| The value of the query parameter must match the regular expression specified by regexMatch.For regular expression grammar, please see https://github.com/google/re2/wiki/Syntax |
| |
| * `present_match` - |
| (Optional) |
| Specifies that the QueryParameterMatcher matches if request contains query parameter, irrespective of whether the parameter has a value or not. |
| |
| <a name="nested_headers"></a>The `headers` block supports: |
| |
| * `header` - |
| (Optional) |
| The name of the HTTP header to match against. |
| |
| * `invert_match` - |
| (Optional) |
| If specified, the match result will be inverted before checking. Default value is set to false. |
| |
| * `exact_match` - |
| (Optional) |
| The value of the header should match exactly the content of exactMatch. |
| |
| * `regex_match` - |
| (Optional) |
| The value of the header must match the regular expression specified in regexMatch. |
| |
| * `prefix_match` - |
| (Optional) |
| The value of the header must start with the contents of prefixMatch. |
| |
| * `present_match` - |
| (Optional) |
| A header with headerName must exist. The match takes place whether or not the header has a value. |
| |
| * `suffix_match` - |
| (Optional) |
| The value of the header must end with the contents of suffixMatch. |
| |
| * `range_match` - |
| (Optional) |
| If specified, the rule will match if the request header value is within the range. |
| Structure is [documented below](#nested_range_match). |
| |
| |
| <a name="nested_range_match"></a>The `range_match` block supports: |
| |
| * `start` - |
| (Required) |
| Start of the range (inclusive). |
| |
| * `end` - |
| (Required) |
| End of the range (exclusive). |
| |
| <a name="nested_action"></a>The `action` block supports: |
| |
| * `destinations` - |
| (Optional) |
| The destination to which traffic should be forwarded. |
| Structure is [documented below](#nested_destinations). |
| |
| * `redirect` - |
| (Optional) |
| If set, the request is directed as configured by this field. |
| Structure is [documented below](#nested_redirect). |
| |
| * `fault_injection_policy` - |
| (Optional) |
| The specification for fault injection introduced into traffic to test the resiliency of clients to backend service failure. |
| Structure is [documented below](#nested_fault_injection_policy). |
| |
| * `request_header_modifier` - |
| (Optional) |
| The specification for modifying the headers of a matching request prior to delivery of the request to the destination. |
| Structure is [documented below](#nested_request_header_modifier). |
| |
| * `response_header_modifier` - |
| (Optional) |
| The specification for modifying the headers of a response prior to sending the response back to the client. |
| Structure is [documented below](#nested_response_header_modifier). |
| |
| * `url_rewrite` - |
| (Optional) |
| The specification for rewrite URL before forwarding requests to the destination. |
| Structure is [documented below](#nested_url_rewrite). |
| |
| * `timeout` - |
| (Optional) |
| Specifies the timeout for selected route. |
| |
| * `retry_policy` - |
| (Optional) |
| Specifies the retry policy associated with this route. |
| Structure is [documented below](#nested_retry_policy). |
| |
| * `request_mirror_policy` - |
| (Optional) |
| Specifies the policy on how requests intended for the routes destination are shadowed to a separate mirrored destination. |
| Structure is [documented below](#nested_request_mirror_policy). |
| |
| * `cors_policy` - |
| (Optional) |
| The specification for allowing client side cross-origin requests. |
| Structure is [documented below](#nested_cors_policy). |
| |
| |
| <a name="nested_destinations"></a>The `destinations` block supports: |
| |
| * `service_name` - |
| (Optional) |
| The URL of a BackendService to route traffic to. |
| |
| * `weight` - |
| (Optional) |
| Specifies the proportion of requests forwarded to the backend referenced by the serviceName field. This is computed as: weight/Sum(weights in this destination list). For non-zero values, there may be some epsilon from the exact proportion defined here depending on the precision an implementation supports. |
| If only one serviceName is specified and it has a weight greater than 0, 100% of the traffic is forwarded to that backend. |
| If weights are specified for any one service name, they need to be specified for all of them. |
| If weights are unspecified for all services, then, traffic is distributed in equal proportions to all of them. |
| |
| <a name="nested_redirect"></a>The `redirect` block supports: |
| |
| * `host_redirect` - |
| (Optional) |
| The host that will be used in the redirect response instead of the one that was supplied in the request. |
| |
| * `path_redirect` - |
| (Optional) |
| The path that will be used in the redirect response instead of the one that was supplied in the request. pathRedirect can not be supplied together with prefixRedirect. Supply one alone or neither. If neither is supplied, the path of the original request will be used for the redirect. |
| |
| * `prefix_rewrite` - |
| (Optional) |
| Indicates that during redirection, the matched prefix (or path) should be swapped with this value. |
| |
| * `response_code` - |
| (Optional) |
| The HTTP Status code to use for the redirect. |
| |
| * `https_redirect` - |
| (Optional) |
| If set to true, the URL scheme in the redirected request is set to https. |
| |
| * `strip_query` - |
| (Optional) |
| If set to true, any accompanying query portion of the original URL is removed prior to redirecting the request. |
| |
| * `port_redirect` - |
| (Optional) |
| The port that will be used in the redirected request instead of the one that was supplied in the request. |
| |
| <a name="nested_fault_injection_policy"></a>The `fault_injection_policy` block supports: |
| |
| * `delay` - |
| (Optional) |
| Specification of how client requests are delayed as part of fault injection before being sent to a destination. |
| Structure is [documented below](#nested_delay). |
| |
| * `abort` - |
| (Optional) |
| Specification of how client requests are aborted as part of fault injection before being sent to a destination. |
| Structure is [documented below](#nested_abort). |
| |
| |
| <a name="nested_delay"></a>The `delay` block supports: |
| |
| * `fixed_delay` - |
| (Optional) |
| Specify a fixed delay before forwarding the request. |
| |
| * `percentage` - |
| (Optional) |
| The percentage of traffic on which delay will be injected. |
| |
| <a name="nested_abort"></a>The `abort` block supports: |
| |
| * `http_status` - |
| (Optional) |
| The HTTP status code used to abort the request. |
| |
| * `percentage` - |
| (Optional) |
| The percentage of traffic which will be aborted. |
| |
| <a name="nested_request_header_modifier"></a>The `request_header_modifier` block supports: |
| |
| * `set` - |
| (Optional) |
| Completely overwrite/replace the headers with given map where key is the name of the header, value is the value of the header. |
| |
| * `add` - |
| (Optional) |
| Add the headers with given map where key is the name of the header, value is the value of the header. |
| |
| * `remove` - |
| (Optional) |
| Remove headers (matching by header names) specified in the list. |
| |
| <a name="nested_response_header_modifier"></a>The `response_header_modifier` block supports: |
| |
| * `set` - |
| (Optional) |
| Completely overwrite/replace the headers with given map where key is the name of the header, value is the value of the header. |
| |
| * `add` - |
| (Optional) |
| Add the headers with given map where key is the name of the header, value is the value of the header. |
| |
| * `remove` - |
| (Optional) |
| Remove headers (matching by header names) specified in the list. |
| |
| <a name="nested_url_rewrite"></a>The `url_rewrite` block supports: |
| |
| * `path_prefix_rewrite` - |
| (Optional) |
| Prior to forwarding the request to the selected destination, the matching portion of the requests path is replaced by this value. |
| |
| * `host_rewrite` - |
| (Optional) |
| Prior to forwarding the request to the selected destination, the requests host header is replaced by this value. |
| |
| <a name="nested_retry_policy"></a>The `retry_policy` block supports: |
| |
| * `retry_conditions` - |
| (Optional) |
| Specifies one or more conditions when this retry policy applies. |
| |
| * `num_retries` - |
| (Optional) |
| Specifies the allowed number of retries. |
| |
| * `per_try_timeout` - |
| (Optional) |
| Specifies a non-zero timeout per retry attempt. A duration in seconds with up to nine fractional digits, ending with 's'. Example: "3.5s". |
| |
| <a name="nested_request_mirror_policy"></a>The `request_mirror_policy` block supports: |
| |
| * `destination` - |
| (Optional) |
| The destination the requests will be mirrored to. |
| Structure is [documented below](#nested_destination). |
| |
| |
| <a name="nested_destination"></a>The `destination` block supports: |
| |
| * `service_name` - |
| (Optional) |
| The URL of a BackendService to route traffic to. |
| |
| * `weight` - |
| (Optional) |
| Specifies the proportion of requests forwarded to the backend referenced by the serviceName field. This is computed as: weight/Sum(weights in this destination list). For non-zero values, there may be some epsilon from the exact proportion defined here depending on the precision an implementation supports. |
| If only one serviceName is specified and it has a weight greater than 0, 100% of the traffic is forwarded to that backend. |
| If weights are specified for any one service name, they need to be specified for all of them. |
| If weights are unspecified for all services, then, traffic is distributed in equal proportions to all of them. |
| |
| <a name="nested_cors_policy"></a>The `cors_policy` block supports: |
| |
| * `allow_origins` - |
| (Optional) |
| Specifies the list of origins that will be allowed to do CORS requests. |
| |
| * `allow_origin_regexes` - |
| (Optional) |
| Specifies the regular expression patterns that match allowed origins. |
| |
| * `allow_methods` - |
| (Optional) |
| Specifies the content for Access-Control-Allow-Methods header. |
| |
| * `allow_headers` - |
| (Optional) |
| Specifies the content for Access-Control-Allow-Headers header. |
| |
| * `expose_headers` - |
| (Optional) |
| Specifies the content for Access-Control-Expose-Headers header. |
| |
| * `max_age` - |
| (Optional) |
| Specifies how long result of a preflight request can be cached in seconds. |
| |
| * `allow_credentials` - |
| (Optional) |
| In response to a preflight request, setting this to true indicates that the actual request can include user credentials. |
| |
| * `disabled` - |
| (Optional) |
| If true, the CORS policy is disabled. The default value is false, which indicates that the CORS policy is in effect. |
| |
| - - - |
| |
| |
| * `labels` - |
| (Optional) |
| Set of label tags associated with the HttpRoute resource. |
| **Note**: This field is non-authoritative, and will only manage the labels present in your configuration. |
| Please refer to the field `effective_labels` for all of the labels present on the resource. |
| |
| * `description` - |
| (Optional) |
| A free-text description of the resource. Max length 1024 characters. |
| |
| * `meshes` - |
| (Optional) |
| Meshes defines a list of meshes this HttpRoute is attached to, as one of the routing rules to route the requests served by the mesh. |
| Each mesh reference should match the pattern: projects/*/locations/global/meshes/<mesh_name>. |
| The attached Mesh should be of a type SIDECAR. |
| |
| * `gateways` - |
| (Optional) |
| Gateways defines a list of gateways this HttpRoute is attached to, as one of the routing rules to route the requests served by the gateway. |
| Each gateway reference should match the pattern: projects/*/locations/global/gateways/<gateway_name> |
| |
| * `project` - (Optional) The ID of the project in which the resource belongs. |
| If it is not provided, the provider project is used. |
| |
| |
| ## Attributes Reference |
| |
| In addition to the arguments listed above, the following computed attributes are exported: |
| |
| * `id` - an identifier for the resource with format `projects/{{project}}/locations/global/httpRoutes/{{name}}` |
| |
| * `self_link` - |
| Server-defined URL of this resource. |
| |
| * `create_time` - |
| Time the HttpRoute was created in UTC. |
| |
| * `update_time` - |
| Time the HttpRoute was updated in UTC. |
| |
| * `terraform_labels` - |
| The combination of labels configured directly on the resource |
| and default labels configured on the provider. |
| |
| * `effective_labels` - |
| All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services. |
| |
| |
| ## Timeouts |
| |
| This resource provides the following |
| [Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options: |
| |
| - `create` - Default is 30 minutes. |
| - `update` - Default is 30 minutes. |
| - `delete` - Default is 30 minutes. |
| |
| ## Import |
| |
| |
| HttpRoute can be imported using any of these accepted formats: |
| |
| * `projects/{{project}}/locations/global/httpRoutes/{{name}}` |
| * `{{project}}/{{name}}` |
| * `{{name}}` |
| |
| |
| In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import HttpRoute using one of the formats above. For example: |
| |
| ```tf |
| import { |
| id = "projects/{{project}}/locations/global/httpRoutes/{{name}}" |
| to = google_network_services_http_route.default |
| } |
| ``` |
| |
| When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), 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](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override). |