TcpRoute is the resource defining how TCP traffic should be routed by a Mesh/Gateway resource.
To get more information about TcpRoute, see:
resource "google_compute_backend_service" "default" {
provider = google-beta
name = "my-backend-service"
health_checks = [google_compute_http_health_check.default.id]
}
resource "google_compute_http_health_check" "default" {
provider = google-beta
name = "backend-service-health-check"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_network_services_tcp_route" "default" {
provider = google-beta
name = "my-tcp-route"
labels = {
foo = "bar"
}
description = "my description"
rules {
matches {
address = "10.0.0.1/32"
port = "8081"
}
action {
destinations {
service_name = google_compute_backend_service.default.id
weight = 1
}
original_destination = false
}
}
}
resource "google_compute_backend_service" "default" {
provider = google-beta
name = "my-backend-service"
health_checks = [google_compute_http_health_check.default.id]
}
resource "google_compute_http_health_check" "default" {
provider = google-beta
name = "backend-service-health-check"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_network_services_tcp_route" "default" {
provider = google-beta
name = "my-tcp-route"
labels = {
foo = "bar"
}
description = "my description"
rules {
action {
destinations {
service_name = google_compute_backend_service.default.id
weight = 1
}
original_destination = false
}
}
}
resource "google_compute_backend_service" "default" {
provider = google-beta
name = "my-backend-service"
health_checks = [google_compute_http_health_check.default.id]
}
resource "google_compute_http_health_check" "default" {
provider = google-beta
name = "backend-service-health-check"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_network_services_mesh" "default" {
provider = google-beta
name = "my-tcp-route"
labels = {
foo = "bar"
}
description = "my description"
}
resource "google_network_services_tcp_route" "default" {
provider = google-beta
name = "my-tcp-route"
labels = {
foo = "bar"
}
description = "my description"
meshes = [
google_network_services_mesh.default.id
]
rules {
matches {
address = "10.0.0.1/32"
port = "8081"
}
action {
destinations {
service_name = google_compute_backend_service.default.id
weight = 1
}
original_destination = false
}
}
}
resource "google_compute_backend_service" "default" {
provider = google-beta
name = "my-backend-service"
health_checks = [google_compute_http_health_check.default.id]
}
resource "google_compute_http_health_check" "default" {
provider = google-beta
name = "backend-service-health-check"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_network_services_gateway" "default" {
provider = google-beta
name = "my-tcp-route"
labels = {
foo = "bar"
}
description = "my description"
scope = "my-scope"
type = "OPEN_MESH"
ports = [443]
}
resource "google_network_services_tcp_route" "default" {
provider = google-beta
name = "my-tcp-route"
labels = {
foo = "bar"
}
description = "my description"
gateways = [
google_network_services_gateway.default.id
]
rules {
matches {
address = "10.0.0.1/32"
port = "8081"
}
action {
destinations {
service_name = google_compute_backend_service.default.id
weight = 1
}
original_destination = false
}
}
}
The following arguments are supported:
rules
-
(Required)
Rules that define how traffic is routed and handled. At least one RouteRule must be supplied.
If there are multiple rules then the action taken will be the first rule to match.
Structure is documented below.
name
-
(Required)
Name of the TcpRoute resource.
matches
-
(Optional)
RouteMatch defines the predicate used to match requests to a given action. Multiple match types are "OR"ed for evaluation.
If no routeMatch field is specified, this rule will unconditionally match traffic.
Structure is documented below.
action
-
(Required)
A detailed rule defining how to route traffic.
Structure is documented below.
address
-
(Required)
Must be specified in the CIDR range format. A CIDR range consists of an IP Address and a prefix length to construct the subnet mask.
By default, the prefix length is 32 (i.e. matches a single IP address). Only IPV4 addresses are supported. Examples: "10.0.0.1" - matches against this exact IP address. "10.0.0.0/8" - matches against any IP address within the 10.0.0.0 subnet and 255.255.255.0 mask. "0.0.0.0/0" - matches against any IP address'.
port
-
(Required)
Specifies the destination port to match against.
destinations
-
(Optional)
The destination services to which traffic should be forwarded. At least one destination service is required.
Structure is documented below.
original_destination
-
(Optional)
If true, Router will use the destination IP and port of the original connection as the destination of the request.
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.
labels
-
(Optional)
Set of label tags associated with the TcpRoute 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 TcpRoute 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/
gateways
-
(Optional)
Gateways defines a list of gateways this TcpRoute 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/
project
- (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.
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/tcpRoutes/{{name}}
self_link
-
Server-defined URL of this resource.
create_time
-
Time the TcpRoute was created in UTC.
update_time
-
Time the TcpRoute 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.
This resource provides the following Timeouts configuration options:
create
- Default is 30 minutes.update
- Default is 30 minutes.delete
- Default is 30 minutes.TcpRoute can be imported using any of these accepted formats:
projects/{{project}}/locations/global/tcpRoutes/{{name}}
{{project}}/{{name}}
{{name}}
In Terraform v1.5.0 and later, use an import
block to import TcpRoute using one of the formats above. For example:
import {
id = "projects/{{project}}/locations/global/tcpRoutes/{{name}}"
to = google_network_services_tcp_route.default
}
When using the terraform import
command, TcpRoute can be imported using one of the formats above. For example:
$ terraform import google_network_services_tcp_route.default projects/{{project}}/locations/global/tcpRoutes/{{name}}
$ terraform import google_network_services_tcp_route.default {{project}}/{{name}}
$ terraform import google_network_services_tcp_route.default {{name}}
This resource supports User Project Overrides.