aws.ec2.getRouteTable
Explore with Pulumi AI
aws.ec2.RouteTable 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 pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const config = new pulumi.Config();
const subnetId = config.requireObject("subnetId");
const selected = aws.ec2.getRouteTable({
    subnetId: subnetId,
});
const route = new aws.ec2.Route("route", {
    routeTableId: selected.then(selected => selected.id),
    destinationCidrBlock: "10.0.1.0/22",
    vpcPeeringConnectionId: "pcx-45ff3dc1",
});
import pulumi
import pulumi_aws as aws
config = pulumi.Config()
subnet_id = config.require_object("subnetId")
selected = aws.ec2.get_route_table(subnet_id=subnet_id)
route = aws.ec2.Route("route",
    route_table_id=selected.id,
    destination_cidr_block="10.0.1.0/22",
    vpc_peering_connection_id="pcx-45ff3dc1")
package main
import (
	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
)
func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		cfg := config.New(ctx, "")
		subnetId := cfg.RequireObject("subnetId")
		selected, err := ec2.LookupRouteTable(ctx, &ec2.LookupRouteTableArgs{
			SubnetId: pulumi.StringRef(subnetId),
		}, nil)
		if err != nil {
			return err
		}
		_, err = ec2.NewRoute(ctx, "route", &ec2.RouteArgs{
			RouteTableId:           pulumi.String(selected.Id),
			DestinationCidrBlock:   pulumi.String("10.0.1.0/22"),
			VpcPeeringConnectionId: pulumi.String("pcx-45ff3dc1"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() => 
{
    var config = new Config();
    var subnetId = config.RequireObject<dynamic>("subnetId");
    var selected = Aws.Ec2.GetRouteTable.Invoke(new()
    {
        SubnetId = subnetId,
    });
    var route = new Aws.Ec2.Route("route", new()
    {
        RouteTableId = selected.Apply(getRouteTableResult => getRouteTableResult.Id),
        DestinationCidrBlock = "10.0.1.0/22",
        VpcPeeringConnectionId = "pcx-45ff3dc1",
    });
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.Ec2Functions;
import com.pulumi.aws.ec2.inputs.GetRouteTableArgs;
import com.pulumi.aws.ec2.Route;
import com.pulumi.aws.ec2.RouteArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }
    public static void stack(Context ctx) {
        final var config = ctx.config();
        final var subnetId = config.get("subnetId");
        final var selected = Ec2Functions.getRouteTable(GetRouteTableArgs.builder()
            .subnetId(subnetId)
            .build());
        var route = new Route("route", RouteArgs.builder()
            .routeTableId(selected.applyValue(getRouteTableResult -> getRouteTableResult.id()))
            .destinationCidrBlock("10.0.1.0/22")
            .vpcPeeringConnectionId("pcx-45ff3dc1")
            .build());
    }
}
configuration:
  subnetId:
    type: dynamic
resources:
  route:
    type: aws:ec2:Route
    properties:
      routeTableId: ${selected.id}
      destinationCidrBlock: 10.0.1.0/22
      vpcPeeringConnectionId: pcx-45ff3dc1
variables:
  selected:
    fn::invoke:
      function: aws:ec2:getRouteTable
      arguments:
        subnetId: ${subnetId}
Using getRouteTable
Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.
function getRouteTable(args: GetRouteTableArgs, opts?: InvokeOptions): Promise<GetRouteTableResult>
function getRouteTableOutput(args: GetRouteTableOutputArgs, opts?: InvokeOptions): Output<GetRouteTableResult>def get_route_table(filters: Optional[Sequence[GetRouteTableFilter]] = None,
                    gateway_id: Optional[str] = None,
                    route_table_id: Optional[str] = None,
                    subnet_id: Optional[str] = None,
                    tags: Optional[Mapping[str, str]] = None,
                    vpc_id: Optional[str] = None,
                    opts: Optional[InvokeOptions] = None) -> GetRouteTableResult
def get_route_table_output(filters: Optional[pulumi.Input[Sequence[pulumi.Input[GetRouteTableFilterArgs]]]] = None,
                    gateway_id: Optional[pulumi.Input[str]] = None,
                    route_table_id: Optional[pulumi.Input[str]] = None,
                    subnet_id: Optional[pulumi.Input[str]] = None,
                    tags: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
                    vpc_id: Optional[pulumi.Input[str]] = None,
                    opts: Optional[InvokeOptions] = None) -> Output[GetRouteTableResult]func LookupRouteTable(ctx *Context, args *LookupRouteTableArgs, opts ...InvokeOption) (*LookupRouteTableResult, error)
func LookupRouteTableOutput(ctx *Context, args *LookupRouteTableOutputArgs, opts ...InvokeOption) LookupRouteTableResultOutput> Note: This function is named LookupRouteTable in the Go SDK.
public static class GetRouteTable 
{
    public static Task<GetRouteTableResult> InvokeAsync(GetRouteTableArgs args, InvokeOptions? opts = null)
    public static Output<GetRouteTableResult> Invoke(GetRouteTableInvokeArgs args, InvokeOptions? opts = null)
}public static CompletableFuture<GetRouteTableResult> getRouteTable(GetRouteTableArgs args, InvokeOptions options)
public static Output<GetRouteTableResult> getRouteTable(GetRouteTableArgs args, InvokeOptions options)
fn::invoke:
  function: aws:ec2/getRouteTable:getRouteTable
  arguments:
    # arguments dictionaryThe following arguments are supported:
- Filters
List<GetRoute Table Filter> 
- Configuration block. Detailed below.
- GatewayId string
- ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
- RouteTable stringId 
- ID of the specific Route Table to retrieve.
- SubnetId string
- ID of a Subnet which is connected to the Route Table (not exported if not passed as a parameter).
- Dictionary<string, string>
- Map of tags, each pair of which must exactly match a pair on the desired Route Table.
- VpcId string
- ID of the VPC that the desired Route Table belongs to.
- Filters
[]GetRoute Table Filter 
- Configuration block. Detailed below.
- GatewayId string
- ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
- RouteTable stringId 
- ID of the specific Route Table to retrieve.
- SubnetId string
- ID of a Subnet which is connected to the Route Table (not exported if not passed as a parameter).
- map[string]string
- Map of tags, each pair of which must exactly match a pair on the desired Route Table.
- VpcId string
- ID of the VPC that the desired Route Table belongs to.
- filters
List<GetRoute Table Filter> 
- Configuration block. Detailed below.
- gatewayId String
- ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
- routeTable StringId 
- ID of the specific Route Table to retrieve.
- subnetId String
- ID of a Subnet which is connected to the Route Table (not exported if not passed as a parameter).
- Map<String,String>
- Map of tags, each pair of which must exactly match a pair on the desired Route Table.
- vpcId String
- ID of the VPC that the desired Route Table belongs to.
- filters
GetRoute Table Filter[] 
- Configuration block. Detailed below.
- gatewayId string
- ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
- routeTable stringId 
- ID of the specific Route Table to retrieve.
- subnetId string
- ID of a Subnet which is connected to the Route Table (not exported if not passed as a parameter).
- {[key: string]: string}
- Map of tags, each pair of which must exactly match a pair on the desired Route Table.
- vpcId string
- ID of the VPC that the desired Route Table belongs to.
- filters
Sequence[GetRoute Table Filter] 
- Configuration block. Detailed below.
- gateway_id str
- ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
- route_table_ strid 
- ID of the specific Route Table to retrieve.
- subnet_id str
- ID of a Subnet which is connected to the Route Table (not exported if not passed as a parameter).
- Mapping[str, str]
- Map of tags, each pair of which must exactly match a pair on the desired Route Table.
- vpc_id str
- ID of the VPC that the desired Route Table belongs to.
- filters List<Property Map>
- Configuration block. Detailed below.
- gatewayId String
- ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
- routeTable StringId 
- ID of the specific Route Table to retrieve.
- subnetId String
- ID of a Subnet which is connected to the Route Table (not exported if not passed as a parameter).
- Map<String>
- Map of tags, each pair of which must exactly match a pair on the desired Route Table.
- vpcId String
- ID of the VPC that the desired Route Table belongs to.
getRouteTable Result
The following output properties are available:
- Arn string
- ARN of the route table.
- Associations
List<GetRoute Table Association> 
- List of associations with attributes detailed below.
- GatewayId string
- Gateway ID. Only set when associated with an Internet Gateway or Virtual Private Gateway.
- Id string
- The provider-assigned unique ID for this managed resource.
- OwnerId string
- ID of the AWS account that owns the route table.
- RouteTable stringId 
- Route Table ID.
- Routes
List<GetRoute Table Route> 
- List of routes with attributes detailed below.
- SubnetId string
- Subnet ID. Only set when associated with a subnet.
- Dictionary<string, string>
- VpcId string
- Filters
List<GetRoute Table Filter> 
- Arn string
- ARN of the route table.
- Associations
[]GetRoute Table Association Type 
- List of associations with attributes detailed below.
- GatewayId string
- Gateway ID. Only set when associated with an Internet Gateway or Virtual Private Gateway.
- Id string
- The provider-assigned unique ID for this managed resource.
- OwnerId string
- ID of the AWS account that owns the route table.
- RouteTable stringId 
- Route Table ID.
- Routes
[]GetRoute Table Route 
- List of routes with attributes detailed below.
- SubnetId string
- Subnet ID. Only set when associated with a subnet.
- map[string]string
- VpcId string
- Filters
[]GetRoute Table Filter 
- arn String
- ARN of the route table.
- associations
List<GetRoute Table Association> 
- List of associations with attributes detailed below.
- gatewayId String
- Gateway ID. Only set when associated with an Internet Gateway or Virtual Private Gateway.
- id String
- The provider-assigned unique ID for this managed resource.
- ownerId String
- ID of the AWS account that owns the route table.
- routeTable StringId 
- Route Table ID.
- routes
List<GetRoute Table Route> 
- List of routes with attributes detailed below.
- subnetId String
- Subnet ID. Only set when associated with a subnet.
- Map<String,String>
- vpcId String
- filters
List<GetRoute Table Filter> 
- arn string
- ARN of the route table.
- associations
GetRoute Table Association[] 
- List of associations with attributes detailed below.
- gatewayId string
- Gateway ID. Only set when associated with an Internet Gateway or Virtual Private Gateway.
- id string
- The provider-assigned unique ID for this managed resource.
- ownerId string
- ID of the AWS account that owns the route table.
- routeTable stringId 
- Route Table ID.
- routes
GetRoute Table Route[] 
- List of routes with attributes detailed below.
- subnetId string
- Subnet ID. Only set when associated with a subnet.
- {[key: string]: string}
- vpcId string
- filters
GetRoute Table Filter[] 
- arn str
- ARN of the route table.
- associations
Sequence[GetRoute Table Association] 
- List of associations with attributes detailed below.
- gateway_id str
- Gateway ID. Only set when associated with an Internet Gateway or Virtual Private Gateway.
- id str
- The provider-assigned unique ID for this managed resource.
- owner_id str
- ID of the AWS account that owns the route table.
- route_table_ strid 
- Route Table ID.
- routes
Sequence[GetRoute Table Route] 
- List of routes with attributes detailed below.
- subnet_id str
- Subnet ID. Only set when associated with a subnet.
- Mapping[str, str]
- vpc_id str
- filters
Sequence[GetRoute Table Filter] 
- arn String
- ARN of the route table.
- associations List<Property Map>
- List of associations with attributes detailed below.
- gatewayId String
- Gateway ID. Only set when associated with an Internet Gateway or Virtual Private Gateway.
- id String
- The provider-assigned unique ID for this managed resource.
- ownerId String
- ID of the AWS account that owns the route table.
- routeTable StringId 
- Route Table ID.
- routes List<Property Map>
- List of routes with attributes detailed below.
- subnetId String
- Subnet ID. Only set when associated with a subnet.
- Map<String>
- vpcId String
- filters List<Property Map>
Supporting Types
GetRouteTableAssociation   
- GatewayId string
- ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
- Main bool
- Whether the association is due to the main route table.
- RouteTable stringAssociation Id 
- Association ID.
- RouteTable stringId 
- ID of the specific Route Table to retrieve.
- SubnetId string
- ID of a Subnet which is connected to the Route Table (not exported if not passed as a parameter).
- GatewayId string
- ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
- Main bool
- Whether the association is due to the main route table.
- RouteTable stringAssociation Id 
- Association ID.
- RouteTable stringId 
- ID of the specific Route Table to retrieve.
- SubnetId string
- ID of a Subnet which is connected to the Route Table (not exported if not passed as a parameter).
- gatewayId String
- ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
- main Boolean
- Whether the association is due to the main route table.
- routeTable StringAssociation Id 
- Association ID.
- routeTable StringId 
- ID of the specific Route Table to retrieve.
- subnetId String
- ID of a Subnet which is connected to the Route Table (not exported if not passed as a parameter).
- gatewayId string
- ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
- main boolean
- Whether the association is due to the main route table.
- routeTable stringAssociation Id 
- Association ID.
- routeTable stringId 
- ID of the specific Route Table to retrieve.
- subnetId string
- ID of a Subnet which is connected to the Route Table (not exported if not passed as a parameter).
- gateway_id str
- ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
- main bool
- Whether the association is due to the main route table.
- route_table_ strassociation_ id 
- Association ID.
- route_table_ strid 
- ID of the specific Route Table to retrieve.
- subnet_id str
- ID of a Subnet which is connected to the Route Table (not exported if not passed as a parameter).
- gatewayId String
- ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
- main Boolean
- Whether the association is due to the main route table.
- routeTable StringAssociation Id 
- Association ID.
- routeTable StringId 
- ID of the specific Route Table to retrieve.
- subnetId String
- ID of a Subnet which is connected to the Route Table (not exported if not passed as a parameter).
GetRouteTableFilter   
- Name string
- Name of the field to filter by, as defined by the underlying AWS API.
- Values List<string>
- Set of values that are accepted for the given field. A Route Table will be selected if any one of the given values matches.
- Name string
- Name of the field to filter by, as defined by the underlying AWS API.
- Values []string
- Set of values that are accepted for the given field. A Route Table will be selected if any one of the given values matches.
- name String
- Name of the field to filter by, as defined by the underlying AWS API.
- values List<String>
- Set of values that are accepted for the given field. A Route Table will be selected if any one of the given values matches.
- name string
- Name of the field to filter by, as defined by the underlying AWS API.
- values string[]
- Set of values that are accepted for the given field. A Route Table will be selected if any one of the given values matches.
- name str
- Name of the field to filter by, as defined by the underlying AWS API.
- values Sequence[str]
- Set of values that are accepted for the given field. A Route Table will be selected if any one of the given values matches.
- name String
- Name of the field to filter by, as defined by the underlying AWS API.
- values List<String>
- Set of values that are accepted for the given field. A Route Table will be selected if any one of the given values matches.
GetRouteTableRoute   
- CarrierGateway stringId 
- ID of the Carrier Gateway.
- CidrBlock string
- CIDR block of the route.
- CoreNetwork stringArn 
- ARN of the core network.
- DestinationPrefix stringList Id 
- The ID of a managed prefix list destination of the route.
- EgressOnly stringGateway Id 
- ID of the Egress Only Internet Gateway.
- GatewayId string
- ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
- InstanceId string
- EC2 instance ID.
- Ipv6CidrBlock string
- IPv6 CIDR block of the route.
- LocalGateway stringId 
- Local Gateway ID.
- NatGateway stringId 
- NAT Gateway ID.
- NetworkInterface stringId 
- ID of the elastic network interface (eni) to use.
- TransitGateway stringId 
- EC2 Transit Gateway ID.
- VpcEndpoint stringId 
- VPC Endpoint ID.
- VpcPeering stringConnection Id 
- VPC Peering ID.
- CarrierGateway stringId 
- ID of the Carrier Gateway.
- CidrBlock string
- CIDR block of the route.
- CoreNetwork stringArn 
- ARN of the core network.
- DestinationPrefix stringList Id 
- The ID of a managed prefix list destination of the route.
- EgressOnly stringGateway Id 
- ID of the Egress Only Internet Gateway.
- GatewayId string
- ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
- InstanceId string
- EC2 instance ID.
- Ipv6CidrBlock string
- IPv6 CIDR block of the route.
- LocalGateway stringId 
- Local Gateway ID.
- NatGateway stringId 
- NAT Gateway ID.
- NetworkInterface stringId 
- ID of the elastic network interface (eni) to use.
- TransitGateway stringId 
- EC2 Transit Gateway ID.
- VpcEndpoint stringId 
- VPC Endpoint ID.
- VpcPeering stringConnection Id 
- VPC Peering ID.
- carrierGateway StringId 
- ID of the Carrier Gateway.
- cidrBlock String
- CIDR block of the route.
- coreNetwork StringArn 
- ARN of the core network.
- destinationPrefix StringList Id 
- The ID of a managed prefix list destination of the route.
- egressOnly StringGateway Id 
- ID of the Egress Only Internet Gateway.
- gatewayId String
- ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
- instanceId String
- EC2 instance ID.
- ipv6CidrBlock String
- IPv6 CIDR block of the route.
- localGateway StringId 
- Local Gateway ID.
- natGateway StringId 
- NAT Gateway ID.
- networkInterface StringId 
- ID of the elastic network interface (eni) to use.
- transitGateway StringId 
- EC2 Transit Gateway ID.
- vpcEndpoint StringId 
- VPC Endpoint ID.
- vpcPeering StringConnection Id 
- VPC Peering ID.
- carrierGateway stringId 
- ID of the Carrier Gateway.
- cidrBlock string
- CIDR block of the route.
- coreNetwork stringArn 
- ARN of the core network.
- destinationPrefix stringList Id 
- The ID of a managed prefix list destination of the route.
- egressOnly stringGateway Id 
- ID of the Egress Only Internet Gateway.
- gatewayId string
- ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
- instanceId string
- EC2 instance ID.
- ipv6CidrBlock string
- IPv6 CIDR block of the route.
- localGateway stringId 
- Local Gateway ID.
- natGateway stringId 
- NAT Gateway ID.
- networkInterface stringId 
- ID of the elastic network interface (eni) to use.
- transitGateway stringId 
- EC2 Transit Gateway ID.
- vpcEndpoint stringId 
- VPC Endpoint ID.
- vpcPeering stringConnection Id 
- VPC Peering ID.
- carrier_gateway_ strid 
- ID of the Carrier Gateway.
- cidr_block str
- CIDR block of the route.
- core_network_ strarn 
- ARN of the core network.
- destination_prefix_ strlist_ id 
- The ID of a managed prefix list destination of the route.
- egress_only_ strgateway_ id 
- ID of the Egress Only Internet Gateway.
- gateway_id str
- ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
- instance_id str
- EC2 instance ID.
- ipv6_cidr_ strblock 
- IPv6 CIDR block of the route.
- local_gateway_ strid 
- Local Gateway ID.
- nat_gateway_ strid 
- NAT Gateway ID.
- network_interface_ strid 
- ID of the elastic network interface (eni) to use.
- transit_gateway_ strid 
- EC2 Transit Gateway ID.
- vpc_endpoint_ strid 
- VPC Endpoint ID.
- vpc_peering_ strconnection_ id 
- VPC Peering ID.
- carrierGateway StringId 
- ID of the Carrier Gateway.
- cidrBlock String
- CIDR block of the route.
- coreNetwork StringArn 
- ARN of the core network.
- destinationPrefix StringList Id 
- The ID of a managed prefix list destination of the route.
- egressOnly StringGateway Id 
- ID of the Egress Only Internet Gateway.
- gatewayId String
- ID of an Internet Gateway or Virtual Private Gateway which is connected to the Route Table (not exported if not passed as a parameter).
- instanceId String
- EC2 instance ID.
- ipv6CidrBlock String
- IPv6 CIDR block of the route.
- localGateway StringId 
- Local Gateway ID.
- natGateway StringId 
- NAT Gateway ID.
- networkInterface StringId 
- ID of the elastic network interface (eni) to use.
- transitGateway StringId 
- EC2 Transit Gateway ID.
- vpcEndpoint StringId 
- VPC Endpoint ID.
- vpcPeering StringConnection Id 
- VPC Peering ID.
Package Details
- Repository
- AWS Classic pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the awsTerraform Provider.