googleComputeRoute
Represents a Route resource.
A route is a rule that specifies how certain packets should be handled by the virtual network. Routes are associated with virtual machines by tag, and the set of routes for a particular virtual machine is called its routing table. For each packet leaving a virtual machine, the system searches that virtual machine's routing table for a single best matching route.
Routes match packets by destination IP address, preferring smaller or more specific ranges over larger ones. If there is a tie, the system selects the route with the smallest priority value. If there is still a tie, it uses the layer three and four packet headers to select just one of the remaining matching routes. The packet is then forwarded as specified by the next_hop field of the winning route -- either to another virtual machine destination, a virtual machine gateway or a Compute Engine-operated gateway. Packets that do not match any route in the sending virtual machine's routing table will be dropped.
A Route resource must have exactly one specification of either nextHopGateway, nextHopInstance, nextHopIp, nextHopVpnTunnel, or nextHopIlb.
To get more information about Route, see:
- API documentation
- How-to Guides
- Using Routes
Example Usage - Route Basic
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleComputeNetworkDefault = new google.computeNetwork.ComputeNetwork(
this,
"default",
{
name: "compute-network",
}
);
const googleComputeRouteDefault = new google.computeRoute.ComputeRoute(
this,
"default_1",
{
dest_range: "15.0.0.0/24",
name: "network-route",
network: googleComputeNetworkDefault.name,
next_hop_ip: "10.132.1.5",
priority: 100,
}
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
googleComputeRouteDefault.overrideLogicalId("default");
Example Usage - Route Ilb
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleComputeHealthCheckHc =
new google.computeHealthCheck.ComputeHealthCheck(this, "hc", {
check_interval_sec: 1,
name: "proxy-health-check",
tcp_health_check: [
{
port: "80",
},
],
timeout_sec: 1,
});
const googleComputeNetworkDefault = new google.computeNetwork.ComputeNetwork(
this,
"default",
{
auto_create_subnetworks: false,
name: "compute-network",
}
);
const googleComputeRegionBackendServiceBackend =
new google.computeRegionBackendService.ComputeRegionBackendService(
this,
"backend",
{
health_checks: [googleComputeHealthCheckHc.id],
name: "compute-backend",
region: "us-central1",
}
);
const googleComputeSubnetworkDefault =
new google.computeSubnetwork.ComputeSubnetwork(this, "default_3", {
ip_cidr_range: "10.0.1.0/24",
name: "compute-subnet",
network: googleComputeNetworkDefault.id,
region: "us-central1",
});
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
googleComputeSubnetworkDefault.overrideLogicalId("default");
const googleComputeForwardingRuleDefault =
new google.computeForwardingRule.ComputeForwardingRule(this, "default_4", {
all_ports: true,
backend_service: googleComputeRegionBackendServiceBackend.id,
load_balancing_scheme: "INTERNAL",
name: "compute-forwarding-rule",
network: googleComputeNetworkDefault.name,
region: "us-central1",
subnetwork: googleComputeSubnetworkDefault.name,
});
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
googleComputeForwardingRuleDefault.overrideLogicalId("default");
new google.computeRoute.ComputeRoute(this, "route-ilb", {
dest_range: "0.0.0.0/0",
name: "route-ilb",
network: googleComputeNetworkDefault.name,
next_hop_ilb: googleComputeForwardingRuleDefault.id,
priority: 2000,
});
Example Usage - Route Ilb Vip
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleComputeHealthCheckHc =
new google.computeHealthCheck.ComputeHealthCheck(this, "hc", {
check_interval_sec: 1,
name: "proxy-health-check",
provider: "${google-beta}",
tcp_health_check: [
{
port: "80",
},
],
timeout_sec: 1,
});
const googleComputeNetworkConsumer = new google.computeNetwork.ComputeNetwork(
this,
"consumer",
{
auto_create_subnetworks: false,
name: "consumer-vpc",
provider: "${google-beta}",
}
);
const googleComputeNetworkProducer = new google.computeNetwork.ComputeNetwork(
this,
"producer",
{
auto_create_subnetworks: false,
name: "producer-vpc",
provider: "${google-beta}",
}
);
const googleComputeNetworkPeeringPeering1 =
new google.computeNetworkPeering.ComputeNetworkPeering(this, "peering1", {
name: "peering-producer-to-consumer",
network: googleComputeNetworkConsumer.id,
peer_network: googleComputeNetworkProducer.id,
provider: "${google-beta}",
});
const googleComputeNetworkPeeringPeering2 =
new google.computeNetworkPeering.ComputeNetworkPeering(this, "peering2", {
name: "peering-consumer-to-producer",
network: googleComputeNetworkProducer.id,
peer_network: googleComputeNetworkConsumer.id,
provider: "${google-beta}",
});
const googleComputeRegionBackendServiceBackend =
new google.computeRegionBackendService.ComputeRegionBackendService(
this,
"backend",
{
health_checks: [googleComputeHealthCheckHc.id],
name: "compute-backend",
provider: "${google-beta}",
region: "us-central1",
}
);
const googleComputeSubnetworkConsumer =
new google.computeSubnetwork.ComputeSubnetwork(this, "consumer_6", {
ip_cidr_range: "10.0.2.0/24",
name: "consumer-subnet",
network: googleComputeNetworkConsumer.id,
provider: "${google-beta}",
region: "us-central1",
});
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
googleComputeSubnetworkConsumer.overrideLogicalId("consumer");
const googleComputeSubnetworkProducer =
new google.computeSubnetwork.ComputeSubnetwork(this, "producer_7", {
ip_cidr_range: "10.0.1.0/24",
name: "producer-subnet",
network: googleComputeNetworkProducer.id,
provider: "${google-beta}",
region: "us-central1",
});
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
googleComputeSubnetworkProducer.overrideLogicalId("producer");
const googleComputeForwardingRuleDefault =
new google.computeForwardingRule.ComputeForwardingRule(this, "default", {
all_ports: true,
backend_service: googleComputeRegionBackendServiceBackend.id,
load_balancing_scheme: "INTERNAL",
name: "compute-forwarding-rule",
network: googleComputeNetworkProducer.name,
provider: "${google-beta}",
region: "us-central1",
subnetwork: googleComputeSubnetworkProducer.name,
});
new google.computeRoute.ComputeRoute(this, "route-ilb", {
depends_on: [
`\${${googleComputeNetworkPeeringPeering1.fqn}}`,
`\${${googleComputeNetworkPeeringPeering2.fqn}}`,
],
dest_range: "0.0.0.0/0",
name: "route-ilb",
network: googleComputeNetworkConsumer.name,
next_hop_ilb: googleComputeForwardingRuleDefault.ipAddress,
priority: 2000,
provider: "${google-beta}",
tags: ["tag1", "tag2"],
});
Argument Reference
The following arguments are supported:
-
destRange
- (Required) The destination range of outgoing packets that this route applies to. Only IPv4 is supported. -
name
- (Required) Name of the resource. Provided by the client when the resource is created. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression[aZ]([AZ09]*[aZ09])?
which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash. -
network
- (Required) The network that this route applies to.
-
description
- (Optional) An optional description of this resource. Provide this property when you create the resource. -
priority
- (Optional) The priority of this route. Priority is used to break ties in cases where there is more than one matching route of equal prefix length. In the case of two routes with equal prefix length, the one with the lowest-numbered priority value wins. Default value is 1000. Valid range is 0 through 65535. -
tags
- (Optional) A list of instance tags to which this route applies. -
nextHopGateway
- (Optional) URL to a gateway that should handle matching packets. Currently, you can only specify the internet gateway, using a full or partial valid URL:https://wwwGoogleapisCom/compute/v1/projects/project/global/gateways/defaultInternetGateway
projects/project/global/gateways/defaultInternetGateway
global/gateways/defaultInternetGateway
- The string
defaultInternetGateway
.
-
nextHopInstance
- (Optional) URL to an instance that should handle matching packets. You can specify this as a full or partial URL. For example:https://wwwGoogleapisCom/compute/v1/projects/project/zones/zone/instances/instance
projects/project/zones/zone/instances/instance
zones/zone/instances/instance
- Just the instance name, with the zone in
nextHopInstanceZone
.
-
nextHopIp
- (Optional) Network IP address of an instance that should handle matching packets. -
nextHopVpnTunnel
- (Optional) URL to a VpnTunnel that should handle matching packets. -
nextHopIlb
- (Optional) The IP address or URL to a forwarding rule of type loadBalancingScheme=INTERNAL that should handle matching packets. With the GA provider you can only specify the forwarding rule as a partial or full URL. For example, the following are all valid values:- 10.128.0.56
- https://www.googleapis.com/compute/v1/projects/project/regions/region/forwardingRules/forwardingRule
- regions/region/forwardingRules/forwardingRule When the beta provider, you can also specify the IP address of a forwarding rule from the same VPC or any peered VPC. Note that this can only be used when the destinationRange is a public (non-RFC 1918) IP CIDR range.
-
project
- (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. -
nextHopInstanceZone
- (Optional whennextHopInstance
is specified) The zone of the instance specified innextHopInstance
. Omit ifnextHopInstance
is specified as a URL.
Attributes Reference
In addition to the arguments listed above, the following computed attributes are exported:
-
id
- an identifier for the resource with formatprojects/{{project}}/global/routes/{{name}}
-
nextHopNetwork
- URL to a Network that should handle matching packets. -
selfLink
- The URI of the created resource.
Timeouts
This resource provides the following Timeouts configuration options:
create
- Default is 20 minutes.delete
- Default is 20 minutes.
Import
Route can be imported using any of these accepted formats:
$ terraform import google_compute_route.default projects/{{project}}/global/routes/{{name}}
$ terraform import google_compute_route.default {{project}}/{{name}}
$ terraform import google_compute_route.default {{name}}
User Project Overrides
This resource supports User Project Overrides.