1. Packages
  2. AWS Classic
  3. API Docs
  4. ec2
  5. getRouteTable

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.28.1 published on Thursday, Mar 28, 2024 by Pulumi

aws.ec2.getRouteTable

Explore with Pulumi AI

aws logo

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.28.1 published on Thursday, Mar 28, 2024 by Pulumi

    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)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: aws:ec2/getRouteTable:getRouteTable
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Filters List<GetRouteTableFilter>
    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).
    RouteTableId string
    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).
    Tags 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 []GetRouteTableFilter
    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).
    RouteTableId string
    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).
    Tags 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<GetRouteTableFilter>
    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).
    routeTableId String
    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).
    tags 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 GetRouteTableFilter[]
    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).
    routeTableId string
    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).
    tags {[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[GetRouteTableFilter]
    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_id str
    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).
    tags 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).
    routeTableId String
    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).
    tags 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<GetRouteTableAssociation>
    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.
    RouteTableId string
    Route Table ID.
    Routes List<GetRouteTableRoute>
    List of routes with attributes detailed below.
    SubnetId string
    Subnet ID. Only set when associated with a subnet.
    Tags Dictionary<string, string>
    VpcId string
    Filters List<GetRouteTableFilter>
    Arn string
    ARN of the route table.
    Associations []GetRouteTableAssociationType
    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.
    RouteTableId string
    Route Table ID.
    Routes []GetRouteTableRoute
    List of routes with attributes detailed below.
    SubnetId string
    Subnet ID. Only set when associated with a subnet.
    Tags map[string]string
    VpcId string
    Filters []GetRouteTableFilter
    arn String
    ARN of the route table.
    associations List<GetRouteTableAssociation>
    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.
    routeTableId String
    Route Table ID.
    routes List<GetRouteTableRoute>
    List of routes with attributes detailed below.
    subnetId String
    Subnet ID. Only set when associated with a subnet.
    tags Map<String,String>
    vpcId String
    filters List<GetRouteTableFilter>
    arn string
    ARN of the route table.
    associations GetRouteTableAssociation[]
    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.
    routeTableId string
    Route Table ID.
    routes GetRouteTableRoute[]
    List of routes with attributes detailed below.
    subnetId string
    Subnet ID. Only set when associated with a subnet.
    tags {[key: string]: string}
    vpcId string
    filters GetRouteTableFilter[]
    arn str
    ARN of the route table.
    associations Sequence[GetRouteTableAssociation]
    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_id str
    Route Table ID.
    routes Sequence[GetRouteTableRoute]
    List of routes with attributes detailed below.
    subnet_id str
    Subnet ID. Only set when associated with a subnet.
    tags Mapping[str, str]
    vpc_id str
    filters Sequence[GetRouteTableFilter]
    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.
    routeTableId String
    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.
    tags 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.
    RouteTableAssociationId string
    Association ID.
    RouteTableId string
    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.
    RouteTableAssociationId string
    Association ID.
    RouteTableId string
    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.
    routeTableAssociationId String
    Association ID.
    routeTableId String
    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.
    routeTableAssociationId string
    Association ID.
    routeTableId string
    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_association_id str
    Association ID.
    route_table_id str
    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.
    routeTableAssociationId String
    Association ID.
    routeTableId String
    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

    CarrierGatewayId string
    ID of the Carrier Gateway.
    CidrBlock string
    CIDR block of the route.
    CoreNetworkArn string
    ARN of the core network.
    DestinationPrefixListId string
    The ID of a managed prefix list destination of the route.
    EgressOnlyGatewayId string
    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.
    LocalGatewayId string
    Local Gateway ID.
    NatGatewayId string
    NAT Gateway ID.
    NetworkInterfaceId string
    ID of the elastic network interface (eni) to use.
    TransitGatewayId string
    EC2 Transit Gateway ID.
    VpcEndpointId string
    VPC Endpoint ID.
    VpcPeeringConnectionId string
    VPC Peering ID.
    CarrierGatewayId string
    ID of the Carrier Gateway.
    CidrBlock string
    CIDR block of the route.
    CoreNetworkArn string
    ARN of the core network.
    DestinationPrefixListId string
    The ID of a managed prefix list destination of the route.
    EgressOnlyGatewayId string
    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.
    LocalGatewayId string
    Local Gateway ID.
    NatGatewayId string
    NAT Gateway ID.
    NetworkInterfaceId string
    ID of the elastic network interface (eni) to use.
    TransitGatewayId string
    EC2 Transit Gateway ID.
    VpcEndpointId string
    VPC Endpoint ID.
    VpcPeeringConnectionId string
    VPC Peering ID.
    carrierGatewayId String
    ID of the Carrier Gateway.
    cidrBlock String
    CIDR block of the route.
    coreNetworkArn String
    ARN of the core network.
    destinationPrefixListId String
    The ID of a managed prefix list destination of the route.
    egressOnlyGatewayId String
    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.
    localGatewayId String
    Local Gateway ID.
    natGatewayId String
    NAT Gateway ID.
    networkInterfaceId String
    ID of the elastic network interface (eni) to use.
    transitGatewayId String
    EC2 Transit Gateway ID.
    vpcEndpointId String
    VPC Endpoint ID.
    vpcPeeringConnectionId String
    VPC Peering ID.
    carrierGatewayId string
    ID of the Carrier Gateway.
    cidrBlock string
    CIDR block of the route.
    coreNetworkArn string
    ARN of the core network.
    destinationPrefixListId string
    The ID of a managed prefix list destination of the route.
    egressOnlyGatewayId string
    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.
    localGatewayId string
    Local Gateway ID.
    natGatewayId string
    NAT Gateway ID.
    networkInterfaceId string
    ID of the elastic network interface (eni) to use.
    transitGatewayId string
    EC2 Transit Gateway ID.
    vpcEndpointId string
    VPC Endpoint ID.
    vpcPeeringConnectionId string
    VPC Peering ID.
    carrier_gateway_id str
    ID of the Carrier Gateway.
    cidr_block str
    CIDR block of the route.
    core_network_arn str
    ARN of the core network.
    destination_prefix_list_id str
    The ID of a managed prefix list destination of the route.
    egress_only_gateway_id str
    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_block str
    IPv6 CIDR block of the route.
    local_gateway_id str
    Local Gateway ID.
    nat_gateway_id str
    NAT Gateway ID.
    network_interface_id str
    ID of the elastic network interface (eni) to use.
    transit_gateway_id str
    EC2 Transit Gateway ID.
    vpc_endpoint_id str
    VPC Endpoint ID.
    vpc_peering_connection_id str
    VPC Peering ID.
    carrierGatewayId String
    ID of the Carrier Gateway.
    cidrBlock String
    CIDR block of the route.
    coreNetworkArn String
    ARN of the core network.
    destinationPrefixListId String
    The ID of a managed prefix list destination of the route.
    egressOnlyGatewayId String
    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.
    localGatewayId String
    Local Gateway ID.
    natGatewayId String
    NAT Gateway ID.
    networkInterfaceId String
    ID of the elastic network interface (eni) to use.
    transitGatewayId String
    EC2 Transit Gateway ID.
    vpcEndpointId String
    VPC Endpoint ID.
    vpcPeeringConnectionId String
    VPC Peering ID.

    Package Details

    Repository
    AWS Classic pulumi/pulumi-aws
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the aws Terraform Provider.
    aws logo

    Try AWS Native preview for resources not in the classic version.

    AWS Classic v6.28.1 published on Thursday, Mar 28, 2024 by Pulumi