Skip to content

Data Source: awsRouteTable

awsRouteTable provides details about a specific Route Table.

This resource can prove useful when a module accepts a Subnet ID as an input variable and needs to, for example, add a route in the Route Table.

Example Usage

The following example shows how one might accept a Route Table ID as a variable and use this data source to obtain the data necessary to create a route.

import * as cdktf from "cdktf";
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
/*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
You can read more about this at https://cdk.tf/variables*/
const subnetId = new cdktf.TerraformVariable(this, "subnet_id", {});
const dataAwsRouteTableSelected = new aws.dataAwsRouteTable.DataAwsRouteTable(
  this,
  "selected",
  {
    subnetId: subnetId.value,
  }
);
new aws.route.Route(this, "route", {
  destinationCidrBlock: "10.0.1.0/22",
  routeTableId: dataAwsRouteTableSelected.id,
  vpcPeeringConnectionId: "pcx-45ff3dc1",
});

Argument Reference

The arguments of this data source act as filters for querying the available Route Table in the current region. The given filters must match exactly one Route Table whose data will be exported as attributes.

The following arguments are optional:

  • filter - (Optional) Configuration block. Detailed below.
  • gatewayId - (Optional) ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
  • routeTableId - (Optional) ID of the specific Route Table to retrieve.
  • subnetId - (Optional) ID of a Subnet which is connected to the Route Table (not exported if not passed as a parameter).
  • tags - (Optional) Map of tags, each pair of which must exactly match a pair on the desired Route Table.
  • vpcId - (Optional) ID of the VPC that the desired Route Table belongs to.

filter

Complex filters can be expressed using one or more filter blocks.

The following arguments are required:

  • name - (Required) Name of the field to filter by, as defined by the underlying AWS API.
  • values - (Required) Set of values that are accepted for the given field. A Route Table will be selected if any one of the given values matches.

Attributes Reference

In addition to the arguments above, the following attributes are exported:

  • arn - ARN of the route table.
  • associations - List of associations with attributes detailed below.
  • ownerId - ID of the AWS account that owns the route table.
  • routes - List of routes with attributes detailed below.

routes

When relevant, routes are also exported with the following attributes:

For destinations:

  • cidrBlock - CIDR block of the route.
  • destinationPrefixListId - The ID of a managed prefix list destination of the route.
  • ipv6CidrBlock - IPv6 CIDR block of the route.

For targets:

  • carrierGatewayId - ID of the Carrier Gateway.
  • coreNetworkArn - ARN of the core network.
  • egressOnlyGatewayId - ID of the Egress Only Internet Gateway.
  • gatewayId - Internet Gateway ID.
  • instanceId - EC2 instance ID.
  • localGatewayId - Local Gateway ID.
  • natGatewayId - NAT Gateway ID.
  • networkInterfaceId - ID of the elastic network interface (eni) to use.
  • transitGatewayId - EC2 Transit Gateway ID.
  • vpcEndpointId - VPC Endpoint ID.
  • vpcPeeringConnectionId - VPC Peering ID.

associations

Associations are also exported with the following attributes:

  • gatewayId - Gateway ID. Only set when associated with an Internet Gateway or Virtual Private Gateway.
  • main - Whether the association is due to the main route table.
  • routeTableAssociationId - Association ID.
  • routeTableId - Route Table ID.
  • subnetId - Subnet ID. Only set when associated with a subnet.

Timeouts

Configuration options:

  • read - (Default 20M)