aws.ec2.getRoute
Explore with Pulumi AI
aws.ec2.Route provides details about a specific Route.
This resource can prove useful when finding the resource associated with a CIDR. For example, finding the peering connection associated with a CIDR value.
Example Usage
The following example shows how one might use a CIDR value to find a network interface id and use this to create a data source of that network interface.
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 = aws.ec2.getRoute({
    routeTableId: selectedAwsRouteTable.id,
    destinationCidrBlock: "10.0.1.0/24",
});
const _interface = route.then(route => aws.ec2.getNetworkInterface({
    id: route.networkInterfaceId,
}));
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.get_route(route_table_id=selected_aws_route_table["id"],
    destination_cidr_block="10.0.1.0/24")
interface = aws.ec2.get_network_interface(id=route.network_interface_id)
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")
		_, err := ec2.LookupRouteTable(ctx, &ec2.LookupRouteTableArgs{
			SubnetId: pulumi.StringRef(subnetId),
		}, nil)
		if err != nil {
			return err
		}
		route, err := ec2.LookupRoute(ctx, &ec2.LookupRouteArgs{
			RouteTableId:         selectedAwsRouteTable.Id,
			DestinationCidrBlock: pulumi.StringRef("10.0.1.0/24"),
		}, nil)
		if err != nil {
			return err
		}
		_, err = ec2.LookupNetworkInterface(ctx, &ec2.LookupNetworkInterfaceArgs{
			Id: pulumi.StringRef(route.NetworkInterfaceId),
		}, nil)
		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 = Aws.Ec2.GetRoute.Invoke(new()
    {
        RouteTableId = selectedAwsRouteTable.Id,
        DestinationCidrBlock = "10.0.1.0/24",
    });
    var @interface = Aws.Ec2.GetNetworkInterface.Invoke(new()
    {
        Id = route.Apply(getRouteResult => getRouteResult.NetworkInterfaceId),
    });
});
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.inputs.GetRouteArgs;
import com.pulumi.aws.ec2.inputs.GetNetworkInterfaceArgs;
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());
        final var route = Ec2Functions.getRoute(GetRouteArgs.builder()
            .routeTableId(selectedAwsRouteTable.id())
            .destinationCidrBlock("10.0.1.0/24")
            .build());
        final var interface = Ec2Functions.getNetworkInterface(GetNetworkInterfaceArgs.builder()
            .id(route.applyValue(getRouteResult -> getRouteResult.networkInterfaceId()))
            .build());
    }
}
configuration:
  subnetId:
    type: dynamic
variables:
  selected:
    fn::invoke:
      function: aws:ec2:getRouteTable
      arguments:
        subnetId: ${subnetId}
  route:
    fn::invoke:
      function: aws:ec2:getRoute
      arguments:
        routeTableId: ${selectedAwsRouteTable.id}
        destinationCidrBlock: 10.0.1.0/24
  interface:
    fn::invoke:
      function: aws:ec2:getNetworkInterface
      arguments:
        id: ${route.networkInterfaceId}
Using getRoute
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 getRoute(args: GetRouteArgs, opts?: InvokeOptions): Promise<GetRouteResult>
function getRouteOutput(args: GetRouteOutputArgs, opts?: InvokeOptions): Output<GetRouteResult>def get_route(carrier_gateway_id: Optional[str] = None,
              core_network_arn: Optional[str] = None,
              destination_cidr_block: Optional[str] = None,
              destination_ipv6_cidr_block: Optional[str] = None,
              destination_prefix_list_id: Optional[str] = None,
              egress_only_gateway_id: Optional[str] = None,
              gateway_id: Optional[str] = None,
              instance_id: Optional[str] = None,
              local_gateway_id: Optional[str] = None,
              nat_gateway_id: Optional[str] = None,
              network_interface_id: Optional[str] = None,
              route_table_id: Optional[str] = None,
              transit_gateway_id: Optional[str] = None,
              vpc_peering_connection_id: Optional[str] = None,
              opts: Optional[InvokeOptions] = None) -> GetRouteResult
def get_route_output(carrier_gateway_id: Optional[pulumi.Input[str]] = None,
              core_network_arn: Optional[pulumi.Input[str]] = None,
              destination_cidr_block: Optional[pulumi.Input[str]] = None,
              destination_ipv6_cidr_block: Optional[pulumi.Input[str]] = None,
              destination_prefix_list_id: Optional[pulumi.Input[str]] = None,
              egress_only_gateway_id: Optional[pulumi.Input[str]] = None,
              gateway_id: Optional[pulumi.Input[str]] = None,
              instance_id: Optional[pulumi.Input[str]] = None,
              local_gateway_id: Optional[pulumi.Input[str]] = None,
              nat_gateway_id: Optional[pulumi.Input[str]] = None,
              network_interface_id: Optional[pulumi.Input[str]] = None,
              route_table_id: Optional[pulumi.Input[str]] = None,
              transit_gateway_id: Optional[pulumi.Input[str]] = None,
              vpc_peering_connection_id: Optional[pulumi.Input[str]] = None,
              opts: Optional[InvokeOptions] = None) -> Output[GetRouteResult]func LookupRoute(ctx *Context, args *LookupRouteArgs, opts ...InvokeOption) (*LookupRouteResult, error)
func LookupRouteOutput(ctx *Context, args *LookupRouteOutputArgs, opts ...InvokeOption) LookupRouteResultOutput> Note: This function is named LookupRoute in the Go SDK.
public static class GetRoute 
{
    public static Task<GetRouteResult> InvokeAsync(GetRouteArgs args, InvokeOptions? opts = null)
    public static Output<GetRouteResult> Invoke(GetRouteInvokeArgs args, InvokeOptions? opts = null)
}public static CompletableFuture<GetRouteResult> getRoute(GetRouteArgs args, InvokeOptions options)
public static Output<GetRouteResult> getRoute(GetRouteArgs args, InvokeOptions options)
fn::invoke:
  function: aws:ec2/getRoute:getRoute
  arguments:
    # arguments dictionaryThe following arguments are supported:
- RouteTable stringId 
- ID of the specific Route Table containing the Route entry. - The following arguments are optional: 
- CarrierGateway stringId 
- EC2 Carrier Gateway ID of the Route belonging to the Route Table.
- CoreNetwork stringArn 
- Core network ARN of the Route belonging to the Route Table.
- DestinationCidr stringBlock 
- CIDR block of the Route belonging to the Route Table.
- DestinationIpv6Cidr stringBlock 
- IPv6 CIDR block of the Route belonging to the Route Table.
- DestinationPrefix stringList Id 
- ID of a managed prefix list destination of the Route belonging to the Route Table.
- EgressOnly stringGateway Id 
- Egress Only Gateway ID of the Route belonging to the Route Table.
- GatewayId string
- Gateway ID of the Route belonging to the Route Table.
- InstanceId string
- Instance ID of the Route belonging to the Route Table.
- LocalGateway stringId 
- Local Gateway ID of the Route belonging to the Route Table.
- NatGateway stringId 
- NAT Gateway ID of the Route belonging to the Route Table.
- NetworkInterface stringId 
- Network Interface ID of the Route belonging to the Route Table.
- TransitGateway stringId 
- EC2 Transit Gateway ID of the Route belonging to the Route Table.
- VpcPeering stringConnection Id 
- VPC Peering Connection ID of the Route belonging to the Route Table.
- RouteTable stringId 
- ID of the specific Route Table containing the Route entry. - The following arguments are optional: 
- CarrierGateway stringId 
- EC2 Carrier Gateway ID of the Route belonging to the Route Table.
- CoreNetwork stringArn 
- Core network ARN of the Route belonging to the Route Table.
- DestinationCidr stringBlock 
- CIDR block of the Route belonging to the Route Table.
- DestinationIpv6Cidr stringBlock 
- IPv6 CIDR block of the Route belonging to the Route Table.
- DestinationPrefix stringList Id 
- ID of a managed prefix list destination of the Route belonging to the Route Table.
- EgressOnly stringGateway Id 
- Egress Only Gateway ID of the Route belonging to the Route Table.
- GatewayId string
- Gateway ID of the Route belonging to the Route Table.
- InstanceId string
- Instance ID of the Route belonging to the Route Table.
- LocalGateway stringId 
- Local Gateway ID of the Route belonging to the Route Table.
- NatGateway stringId 
- NAT Gateway ID of the Route belonging to the Route Table.
- NetworkInterface stringId 
- Network Interface ID of the Route belonging to the Route Table.
- TransitGateway stringId 
- EC2 Transit Gateway ID of the Route belonging to the Route Table.
- VpcPeering stringConnection Id 
- VPC Peering Connection ID of the Route belonging to the Route Table.
- routeTable StringId 
- ID of the specific Route Table containing the Route entry. - The following arguments are optional: 
- carrierGateway StringId 
- EC2 Carrier Gateway ID of the Route belonging to the Route Table.
- coreNetwork StringArn 
- Core network ARN of the Route belonging to the Route Table.
- destinationCidr StringBlock 
- CIDR block of the Route belonging to the Route Table.
- destinationIpv6Cidr StringBlock 
- IPv6 CIDR block of the Route belonging to the Route Table.
- destinationPrefix StringList Id 
- ID of a managed prefix list destination of the Route belonging to the Route Table.
- egressOnly StringGateway Id 
- Egress Only Gateway ID of the Route belonging to the Route Table.
- gatewayId String
- Gateway ID of the Route belonging to the Route Table.
- instanceId String
- Instance ID of the Route belonging to the Route Table.
- localGateway StringId 
- Local Gateway ID of the Route belonging to the Route Table.
- natGateway StringId 
- NAT Gateway ID of the Route belonging to the Route Table.
- networkInterface StringId 
- Network Interface ID of the Route belonging to the Route Table.
- transitGateway StringId 
- EC2 Transit Gateway ID of the Route belonging to the Route Table.
- vpcPeering StringConnection Id 
- VPC Peering Connection ID of the Route belonging to the Route Table.
- routeTable stringId 
- ID of the specific Route Table containing the Route entry. - The following arguments are optional: 
- carrierGateway stringId 
- EC2 Carrier Gateway ID of the Route belonging to the Route Table.
- coreNetwork stringArn 
- Core network ARN of the Route belonging to the Route Table.
- destinationCidr stringBlock 
- CIDR block of the Route belonging to the Route Table.
- destinationIpv6Cidr stringBlock 
- IPv6 CIDR block of the Route belonging to the Route Table.
- destinationPrefix stringList Id 
- ID of a managed prefix list destination of the Route belonging to the Route Table.
- egressOnly stringGateway Id 
- Egress Only Gateway ID of the Route belonging to the Route Table.
- gatewayId string
- Gateway ID of the Route belonging to the Route Table.
- instanceId string
- Instance ID of the Route belonging to the Route Table.
- localGateway stringId 
- Local Gateway ID of the Route belonging to the Route Table.
- natGateway stringId 
- NAT Gateway ID of the Route belonging to the Route Table.
- networkInterface stringId 
- Network Interface ID of the Route belonging to the Route Table.
- transitGateway stringId 
- EC2 Transit Gateway ID of the Route belonging to the Route Table.
- vpcPeering stringConnection Id 
- VPC Peering Connection ID of the Route belonging to the Route Table.
- route_table_ strid 
- ID of the specific Route Table containing the Route entry. - The following arguments are optional: 
- carrier_gateway_ strid 
- EC2 Carrier Gateway ID of the Route belonging to the Route Table.
- core_network_ strarn 
- Core network ARN of the Route belonging to the Route Table.
- destination_cidr_ strblock 
- CIDR block of the Route belonging to the Route Table.
- destination_ipv6_ strcidr_ block 
- IPv6 CIDR block of the Route belonging to the Route Table.
- destination_prefix_ strlist_ id 
- ID of a managed prefix list destination of the Route belonging to the Route Table.
- egress_only_ strgateway_ id 
- Egress Only Gateway ID of the Route belonging to the Route Table.
- gateway_id str
- Gateway ID of the Route belonging to the Route Table.
- instance_id str
- Instance ID of the Route belonging to the Route Table.
- local_gateway_ strid 
- Local Gateway ID of the Route belonging to the Route Table.
- nat_gateway_ strid 
- NAT Gateway ID of the Route belonging to the Route Table.
- network_interface_ strid 
- Network Interface ID of the Route belonging to the Route Table.
- transit_gateway_ strid 
- EC2 Transit Gateway ID of the Route belonging to the Route Table.
- vpc_peering_ strconnection_ id 
- VPC Peering Connection ID of the Route belonging to the Route Table.
- routeTable StringId 
- ID of the specific Route Table containing the Route entry. - The following arguments are optional: 
- carrierGateway StringId 
- EC2 Carrier Gateway ID of the Route belonging to the Route Table.
- coreNetwork StringArn 
- Core network ARN of the Route belonging to the Route Table.
- destinationCidr StringBlock 
- CIDR block of the Route belonging to the Route Table.
- destinationIpv6Cidr StringBlock 
- IPv6 CIDR block of the Route belonging to the Route Table.
- destinationPrefix StringList Id 
- ID of a managed prefix list destination of the Route belonging to the Route Table.
- egressOnly StringGateway Id 
- Egress Only Gateway ID of the Route belonging to the Route Table.
- gatewayId String
- Gateway ID of the Route belonging to the Route Table.
- instanceId String
- Instance ID of the Route belonging to the Route Table.
- localGateway StringId 
- Local Gateway ID of the Route belonging to the Route Table.
- natGateway StringId 
- NAT Gateway ID of the Route belonging to the Route Table.
- networkInterface StringId 
- Network Interface ID of the Route belonging to the Route Table.
- transitGateway StringId 
- EC2 Transit Gateway ID of the Route belonging to the Route Table.
- vpcPeering StringConnection Id 
- VPC Peering Connection ID of the Route belonging to the Route Table.
getRoute Result
The following output properties are available:
- CarrierGateway stringId 
- CoreNetwork stringArn 
- DestinationCidr stringBlock 
- DestinationIpv6Cidr stringBlock 
- DestinationPrefix stringList Id 
- EgressOnly stringGateway Id 
- GatewayId string
- Id string
- The provider-assigned unique ID for this managed resource.
- InstanceId string
- LocalGateway stringId 
- NatGateway stringId 
- NetworkInterface stringId 
- RouteTable stringId 
- TransitGateway stringId 
- VpcPeering stringConnection Id 
- CarrierGateway stringId 
- CoreNetwork stringArn 
- DestinationCidr stringBlock 
- DestinationIpv6Cidr stringBlock 
- DestinationPrefix stringList Id 
- EgressOnly stringGateway Id 
- GatewayId string
- Id string
- The provider-assigned unique ID for this managed resource.
- InstanceId string
- LocalGateway stringId 
- NatGateway stringId 
- NetworkInterface stringId 
- RouteTable stringId 
- TransitGateway stringId 
- VpcPeering stringConnection Id 
- carrierGateway StringId 
- coreNetwork StringArn 
- destinationCidr StringBlock 
- destinationIpv6Cidr StringBlock 
- destinationPrefix StringList Id 
- egressOnly StringGateway Id 
- gatewayId String
- id String
- The provider-assigned unique ID for this managed resource.
- instanceId String
- localGateway StringId 
- natGateway StringId 
- networkInterface StringId 
- routeTable StringId 
- transitGateway StringId 
- vpcPeering StringConnection Id 
- carrierGateway stringId 
- coreNetwork stringArn 
- destinationCidr stringBlock 
- destinationIpv6Cidr stringBlock 
- destinationPrefix stringList Id 
- egressOnly stringGateway Id 
- gatewayId string
- id string
- The provider-assigned unique ID for this managed resource.
- instanceId string
- localGateway stringId 
- natGateway stringId 
- networkInterface stringId 
- routeTable stringId 
- transitGateway stringId 
- vpcPeering stringConnection Id 
- carrier_gateway_ strid 
- core_network_ strarn 
- destination_cidr_ strblock 
- destination_ipv6_ strcidr_ block 
- destination_prefix_ strlist_ id 
- egress_only_ strgateway_ id 
- gateway_id str
- id str
- The provider-assigned unique ID for this managed resource.
- instance_id str
- local_gateway_ strid 
- nat_gateway_ strid 
- network_interface_ strid 
- route_table_ strid 
- transit_gateway_ strid 
- vpc_peering_ strconnection_ id 
- carrierGateway StringId 
- coreNetwork StringArn 
- destinationCidr StringBlock 
- destinationIpv6Cidr StringBlock 
- destinationPrefix StringList Id 
- egressOnly StringGateway Id 
- gatewayId String
- id String
- The provider-assigned unique ID for this managed resource.
- instanceId String
- localGateway StringId 
- natGateway StringId 
- networkInterface StringId 
- routeTable StringId 
- transitGateway StringId 
- vpcPeering StringConnection Id 
Package Details
- Repository
- AWS Classic pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the awsTerraform Provider.