AWS Amazon EC2 Route

This page shows how to write Terraform and CloudFormation for Amazon EC2 Route and write them securely.


Fix issues in your cloud & app configurations

Test for misconfigurations of this resource in your cloud.


Terraform Example (aws_route)

Provides a resource to create a routing table entry (a route) in a VPC routing table.

NOTE on Route Tables and Routes: Terraform currently provides both a standalone Route resource and a Route Table resource with routes defined in-line. At this time you cannot use a Route Table with in-line routes in conjunction with any Route resources. Doing so will cause a conflict of rule settings and will overwrite rules. NOTE on gateway_id attribute: The AWS API is very forgiving with the resource ID passed in the gateway_id attribute. For example an aws_route resource can be created with an aws_nat_gateway or aws_egress_only_internet_gateway ID specified for the gateway_id attribute. Specifying anything other than an aws_internet_gateway or aws_vpn_gateway ID will lead to Terraform reporting a permanent diff between your configuration and recorded state, as the AWS API returns the more-specific attribute. If you are experiencing constant diffs with an aws_route resource, the first thing to check is that the correct attribute is being specified.


Example Usage (from GitHub)

resource "aws_route" "source-route-private" {
  provider                  = aws.source
  route_table_id            = var.source-route_table-private-id
  destination_cidr_block    = data.aws_vpc.peer.cidr_block
  vpc_peering_connection_id =
resource "aws_route" "bastion_vpc_dr" {
  provider                  =
  count                     = length(module.dr_cluster.public_subnets)
  route_table_id            = module.primary_cluster.bastion_route_table
  destination_cidr_block    = element(module.dr_cluster.public_subnets, count.index)
  vpc_peering_connection_id =
resource "aws_route" "public_internet_gateway_a" {
  route_table_id         =
  destination_cidr_block = ""
  gateway_id             =

  timeouts {
resource "aws_route" "ngw-default-route" {
  for_each = {for sd in>sd
           if sd.layer == "ngw" }
  route_table_id         = aws_route_table.routers[].id
  destination_cidr_block = ""
  gateway_id             =

CloudFormation Example (AWS::EC2::Route)

Specifies a route in a route table within a VPC.

You must specify either DestinationCidrBlock or DestinationIpv6CidrBlock, plus the ID of one of the target resources.

If you create a route that references a transit gateway in the same template where you create the transit gateway, you must declare a dependency on the transit gateway attachment. The route table cannot use the transit gateway until it has successfully attached to the VPC. Add a DependsOn Attribute in the AWS::EC2::Route resource to explicitly declare a dependency on the AWS::EC2::TransitGatewayAttachment resource.


Frequently asked questions

What is AWS Amazon EC2 Route?

AWS Amazon EC2 Route is a resource for Amazon EC2 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS Amazon EC2 Route?

For Terraform, the atc-labs/terraform-aws-vpc-peering, bstascavage/terraform-vault-consul-deployment and annagtaraujo/Terraform-Transit-Gateway source code examples are useful. See the Terraform Example section for further details.