AWS Amazon EC2 Transit Gateway Route

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

aws_ec2_transit_gateway_route (Terraform)

The Transit Gateway Route in Amazon EC2 can be configured in Terraform with the resource name aws_ec2_transit_gateway_route. The following sections describe 5 examples of how to use the resource and its parameters.

Example Usage from GitHub

main.tf#L8
resource "aws_ec2_transit_gateway_route" "vpc1" {
  destination_cidr_block = "10.10.0.0/19"
  transit_gateway_route_table_id = data.aws_ec2_transit_gateway_route_table.this.id
  transit_gateway_attachment_id  = "tgw-attach-042344e68c52304b5"
}

main.tf#L8
resource "aws_ec2_transit_gateway_route" "vpc1" {
  destination_cidr_block = "10.10.0.0/19"
  transit_gateway_route_table_id = data.aws_ec2_transit_gateway_route_table.this.id
  transit_gateway_attachment_id  = "tgw-attach-042344e68c52304b5"
}

TGW.tf#L127
resource "aws_ec2_transit_gateway_route" "Apps_Default_route" {
  destination_cidr_block = "0.0.0.0/0"
  transit_gateway_attachment_id = aws_ec2_transit_gateway_vpc_attachment.TGW-attach-Egress.id
  transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.Apps_RT.id
}
// Blackhole routes
transit-gateway.tf#L70
resource "aws_ec2_transit_gateway_route" "inspection_vpc_route" {
  transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.egress_rt_table.id
  destination_cidr_block         = "0.0.0.0/0"
  transit_gateway_attachment_id  = module.tgw.ec2_transit_gateway_vpc_attachment["inspection_vpc"]["id"]
  blackhole                      = false

transit_gateway.tf#L20
resource "aws_ec2_transit_gateway_route" "source_vpc" {
  destination_cidr_block         = module.source_vpc.vpc_cidr_block
  transit_gateway_attachment_id  = aws_ec2_transit_gateway_vpc_attachment.source_vpc.id
  transit_gateway_route_table_id = aws_ec2_transit_gateway.this.association_default_route_table_id
}

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Manages an EC2 Transit Gateway Route.

Tips: Best Practices for The Other AWS Amazon EC2 Resources

In addition to the aws_default_vpc, AWS Amazon EC2 has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

aws_default_vpc

Ensure to avoid using default VPC

It is better to define the own VPC and use it.

risk-label

aws_network_acl_rule

Ensure your network ACL rule blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

risk-label

aws_ebs_volume

Ensure to use a customer-managed key for EBS volume encryption

It is better to use a customer-managed key for EBS volume encryption. It can be gain more control over the encryption by using customer-managed keys (CMK).

risk-label

aws_instance

Ensure to avoid storing AWS access keys in user data

It is better to avoid storing AWS access keys in user data. `aws_iam_instance_profile` could be used instead.

risk-label

aws_security_group

Ensure your security group blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

Review your AWS Amazon EC2 settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

AWS::EC2::TransitGatewayRoute (CloudFormation)

The TransitGatewayRoute in EC2 can be configured in CloudFormation with the resource name AWS::EC2::TransitGatewayRoute. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

4.Case2-GWLBTGW.yml#L61
    Type: "AWS::EC2::TransitGatewayRouteTable"
    Properties:
      Tags:
        - Key: Name
          Value: !Sub '${AWS::StackName}-RT-VPC-IN'
      TransitGatewayId: !Ref TransitGatewayGWLB
TGW%20route%20modify.yml#L29
    Type: AWS::EC2::TransitGatewayRoute
    Properties:
      DestinationCidrBlock: 10.0.0.0/8
      TransitGatewayAttachmentId: !ImportValue
        'Fn::Sub': '${InspectionVPCStackName}-TGW-Att'
      TransitGatewayRouteTableId: !ImportValue
app-isolated-dev.yml#L20
    Type: AWS::EC2::TransitGatewayRouteTableAssociation
    Properties:
      TransitGatewayAttachmentId: !Ref NewAttachmentID
      TransitGatewayRouteTableId: !ImportValue AppIsolatedDevTGWRTID

################
app-isolated-prod.yml#L20
    Type: AWS::EC2::TransitGatewayRouteTableAssociation
    Properties:
      TransitGatewayAttachmentId: !Ref NewAttachmentID
      TransitGatewayRouteTableId: !ImportValue AppIsolatedProdTGWRTID

################
tgw-env-route-association-propagation.yml#L16
        Type: AWS::EC2::TransitGatewayRouteTablePropagation
        Properties:
            TransitGatewayAttachmentId: !Ref VPNTransitGatewayAttachment
            TransitGatewayRouteTableId: !Ref EnvTGRTable

    Route:
transitgateway.json#L34
              "Type" : "AWS::EC2::TransitGatewayRouteTable",
              "Properties" : {
                  "TransitGatewayId" : { "Ref" : "transitGatewayId" },
                  "Tags": [
                        {
                            "Key": "Name",
EC2TransitGatewayRouteSpecification.json#L3
    "AWS::EC2::TransitGatewayRoute": {
      "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-transitgatewayroute.html",
      "Properties": {
        "TransitGatewayRouteTableId": {
          "Required": true,
          "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-transitgatewayroute.html#cfn-ec2-transitgatewayroute-transitgatewayroutetableid",
EC2TransitGatewayRouteSpecification.json#L3
    "AWS::EC2::TransitGatewayRoute": {
      "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-transitgatewayroute.html",
      "Properties": {
        "TransitGatewayRouteTableId": {
          "Required": true,
          "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-transitgatewayroute.html#cfn-ec2-transitgatewayroute-transitgatewayroutetableid",
EC2TransitGatewayRouteSpecification.json#L3
    "AWS::EC2::TransitGatewayRoute": {
      "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-transitgatewayroute.html",
      "Properties": {
        "TransitGatewayRouteTableId": {
          "Required": true,
          "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-transitgatewayroute.html#cfn-ec2-transitgatewayroute-transitgatewayroutetableid",
EC2TransitGatewayRouteSpecification.json#L3
    "AWS::EC2::TransitGatewayRoute": {
      "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-transitgatewayroute.html",
      "Properties": {
        "TransitGatewayRouteTableId": {
          "Required": true,
          "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-transitgatewayroute.html#cfn-ec2-transitgatewayroute-transitgatewayroutetableid",

Parameters

Explanation in CloudFormation Registry

Specifies a static route for a transit gateway route table.

Frequently asked questions

What is AWS Amazon EC2 Transit Gateway Route?

AWS Amazon EC2 Transit Gateway 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 Transit Gateway Route?

For Terraform, the dipendrachaudhary/chcs-test, dipendrachaudhary/chcs-test and gchek/egress-vpc source code examples are useful. See the Terraform Example section for further details.

For CloudFormation, the whchoi98/gwlb, vagira/Granular-Security-with-AWS-Network-Firewall-and-Transit-Gateway and JeremieRodon/TransitGatewayAutomation source code examples are useful. See the CloudFormation Example section for further details.