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

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

AWS Classic v6.41.0 published on Tuesday, Jun 18, 2024 by Pulumi

aws.ec2.getRouteTables

Explore with Pulumi AI

aws logo

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

AWS Classic v6.41.0 published on Tuesday, Jun 18, 2024 by Pulumi

    This resource can be useful for getting back a list of route table ids to be referenced elsewhere.

    Example Usage

    The following adds a route for a particular cidr block to every (private kops) route table in a specified vpc to use a particular vpc peering connection.

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    export = async () => {
        const rts = await aws.ec2.getRouteTables({
            vpcId: vpcId,
            filters: [{
                name: "tag:kubernetes.io/kops/role",
                values: ["private*"],
            }],
        });
        const r: aws.ec2.Route[] = [];
        for (const range = {value: 0}; range.value < rts.ids.length; range.value++) {
            r.push(new aws.ec2.Route(`r-${range.value}`, {
                routeTableId: rts.ids[range.value],
                destinationCidrBlock: "10.0.0.0/22",
                vpcPeeringConnectionId: "pcx-0e9a7a9ecd137dc54",
            }));
        }
    }
    
    import pulumi
    import pulumi_aws as aws
    
    rts = aws.ec2.get_route_tables(vpc_id=vpc_id,
        filters=[aws.ec2.GetRouteTablesFilterArgs(
            name="tag:kubernetes.io/kops/role",
            values=["private*"],
        )])
    r = []
    for range in [{"value": i} for i in range(0, len(rts.ids))]:
        r.append(aws.ec2.Route(f"r-{range['value']}",
            route_table_id=rts.ids[range["value"]],
            destination_cidr_block="10.0.0.0/22",
            vpc_peering_connection_id="pcx-0e9a7a9ecd137dc54"))
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		rts, err := ec2.GetRouteTables(ctx, &ec2.GetRouteTablesArgs{
    			VpcId: pulumi.StringRef(vpcId),
    			Filters: []ec2.GetRouteTablesFilter{
    				{
    					Name: "tag:kubernetes.io/kops/role",
    					Values: []string{
    						"private*",
    					},
    				},
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		var r []*ec2.Route
    		for index := 0; index < len(rts.Ids); index++ {
    			key0 := index
    			val0 := index
    			__res, err := ec2.NewRoute(ctx, fmt.Sprintf("r-%v", key0), &ec2.RouteArgs{
    				RouteTableId:           rts.Ids[val0],
    				DestinationCidrBlock:   pulumi.String("10.0.0.0/22"),
    				VpcPeeringConnectionId: pulumi.String("pcx-0e9a7a9ecd137dc54"),
    			})
    			if err != nil {
    				return err
    			}
    			r = append(r, __res)
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(async() => 
    {
        var rts = await Aws.Ec2.GetRouteTables.InvokeAsync(new()
        {
            VpcId = vpcId,
            Filters = new[]
            {
                new Aws.Ec2.Inputs.GetRouteTablesFilterInputArgs
                {
                    Name = "tag:kubernetes.io/kops/role",
                    Values = new[]
                    {
                        "private*",
                    },
                },
            },
        });
    
        var r = new List<Aws.Ec2.Route>();
        for (var rangeIndex = 0; rangeIndex < rts.Ids.Length; rangeIndex++)
        {
            var range = new { Value = rangeIndex };
            r.Add(new Aws.Ec2.Route($"r-{range.Value}", new()
            {
                RouteTableId = rts.Ids[range.Value],
                DestinationCidrBlock = "10.0.0.0/22",
                VpcPeeringConnectionId = "pcx-0e9a7a9ecd137dc54",
            }));
        }
    });
    
    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.GetRouteTablesArgs;
    import com.pulumi.aws.ec2.Route;
    import com.pulumi.aws.ec2.RouteArgs;
    import com.pulumi.codegen.internal.KeyedValue;
    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 rts = Ec2Functions.getRouteTables(GetRouteTablesArgs.builder()
                .vpcId(vpcId)
                .filters(GetRouteTablesFilterArgs.builder()
                    .name("tag:kubernetes.io/kops/role")
                    .values("private*")
                    .build())
                .build());
    
            for (var i = 0; i < rts.applyValue(getRouteTablesResult -> getRouteTablesResult.ids()).length(); i++) {
                new Route("r-" + i, RouteArgs.builder()
                    .routeTableId(rts.applyValue(getRouteTablesResult -> getRouteTablesResult.ids())[range.value()])
                    .destinationCidrBlock("10.0.0.0/22")
                    .vpcPeeringConnectionId("pcx-0e9a7a9ecd137dc54")
                    .build());
    
            
    }
        }
    }
    
    Coming soon!
    

    Using getRouteTables

    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 getRouteTables(args: GetRouteTablesArgs, opts?: InvokeOptions): Promise<GetRouteTablesResult>
    function getRouteTablesOutput(args: GetRouteTablesOutputArgs, opts?: InvokeOptions): Output<GetRouteTablesResult>
    def get_route_tables(filters: Optional[Sequence[GetRouteTablesFilter]] = None,
                         tags: Optional[Mapping[str, str]] = None,
                         vpc_id: Optional[str] = None,
                         opts: Optional[InvokeOptions] = None) -> GetRouteTablesResult
    def get_route_tables_output(filters: Optional[pulumi.Input[Sequence[pulumi.Input[GetRouteTablesFilterArgs]]]] = None,
                         tags: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
                         vpc_id: Optional[pulumi.Input[str]] = None,
                         opts: Optional[InvokeOptions] = None) -> Output[GetRouteTablesResult]
    func GetRouteTables(ctx *Context, args *GetRouteTablesArgs, opts ...InvokeOption) (*GetRouteTablesResult, error)
    func GetRouteTablesOutput(ctx *Context, args *GetRouteTablesOutputArgs, opts ...InvokeOption) GetRouteTablesResultOutput

    > Note: This function is named GetRouteTables in the Go SDK.

    public static class GetRouteTables 
    {
        public static Task<GetRouteTablesResult> InvokeAsync(GetRouteTablesArgs args, InvokeOptions? opts = null)
        public static Output<GetRouteTablesResult> Invoke(GetRouteTablesInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetRouteTablesResult> getRouteTables(GetRouteTablesArgs args, InvokeOptions options)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: aws:ec2/getRouteTables:getRouteTables
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Filters List<GetRouteTablesFilter>
    Custom filter block as described below.
    Tags Dictionary<string, string>

    Map of tags, each pair of which must exactly match a pair on the desired route tables.

    More complex filters can be expressed using one or more filter sub-blocks, which take the following arguments:

    VpcId string
    VPC ID that you want to filter from.
    Filters []GetRouteTablesFilter
    Custom filter block as described below.
    Tags map[string]string

    Map of tags, each pair of which must exactly match a pair on the desired route tables.

    More complex filters can be expressed using one or more filter sub-blocks, which take the following arguments:

    VpcId string
    VPC ID that you want to filter from.
    filters List<GetRouteTablesFilter>
    Custom filter block as described below.
    tags Map<String,String>

    Map of tags, each pair of which must exactly match a pair on the desired route tables.

    More complex filters can be expressed using one or more filter sub-blocks, which take the following arguments:

    vpcId String
    VPC ID that you want to filter from.
    filters GetRouteTablesFilter[]
    Custom filter block as described below.
    tags {[key: string]: string}

    Map of tags, each pair of which must exactly match a pair on the desired route tables.

    More complex filters can be expressed using one or more filter sub-blocks, which take the following arguments:

    vpcId string
    VPC ID that you want to filter from.
    filters Sequence[GetRouteTablesFilter]
    Custom filter block as described below.
    tags Mapping[str, str]

    Map of tags, each pair of which must exactly match a pair on the desired route tables.

    More complex filters can be expressed using one or more filter sub-blocks, which take the following arguments:

    vpc_id str
    VPC ID that you want to filter from.
    filters List<Property Map>
    Custom filter block as described below.
    tags Map<String>

    Map of tags, each pair of which must exactly match a pair on the desired route tables.

    More complex filters can be expressed using one or more filter sub-blocks, which take the following arguments:

    vpcId String
    VPC ID that you want to filter from.

    getRouteTables Result

    The following output properties are available:

    Id string
    The provider-assigned unique ID for this managed resource.
    Ids List<string>
    List of all the route table ids found.
    Tags Dictionary<string, string>
    Filters List<GetRouteTablesFilter>
    VpcId string
    Id string
    The provider-assigned unique ID for this managed resource.
    Ids []string
    List of all the route table ids found.
    Tags map[string]string
    Filters []GetRouteTablesFilter
    VpcId string
    id String
    The provider-assigned unique ID for this managed resource.
    ids List<String>
    List of all the route table ids found.
    tags Map<String,String>
    filters List<GetRouteTablesFilter>
    vpcId String
    id string
    The provider-assigned unique ID for this managed resource.
    ids string[]
    List of all the route table ids found.
    tags {[key: string]: string}
    filters GetRouteTablesFilter[]
    vpcId string
    id str
    The provider-assigned unique ID for this managed resource.
    ids Sequence[str]
    List of all the route table ids found.
    tags Mapping[str, str]
    filters Sequence[GetRouteTablesFilter]
    vpc_id str
    id String
    The provider-assigned unique ID for this managed resource.
    ids List<String>
    List of all the route table ids found.
    tags Map<String>
    filters List<Property Map>
    vpcId String

    Supporting Types

    GetRouteTablesFilter

    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.

    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.41.0 published on Tuesday, Jun 18, 2024 by Pulumi