AWS Amazon EC2 Transit Gateway Peering Attachment

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

aws_ec2_transit_gateway_peering_attachment (Terraform)

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

Example Usage from GitHub

tgw-peering-create.tf#L5
resource "aws_ec2_transit_gateway_peering_attachment" "euw1_euw2" {
  provider = aws.eu-west-1

  peer_region             = "eu-west-2"
  peer_transit_gateway_id = data.aws_ec2_transit_gateway.eu_west_2.id
  transit_gateway_id      = data.aws_ec2_transit_gateway.eu_west_1.id
main.tf#L1
resource "aws_ec2_transit_gateway_peering_attachment" "this" {
  peer_account_id         = var.peer_account_id
  peer_region             = var.peer_region
  peer_transit_gateway_id = var.peer_transit_gateway_id
  transit_gateway_id      = var.transit_gateway_id
  tags                    = var.tags
main.tf#L1
resource "aws_ec2_transit_gateway_peering_attachment" "this" {
  peer_account_id         = var.peer_account_id
  peer_region             = var.peer_region
  peer_transit_gateway_id = var.peer_transit_gateway_id
  transit_gateway_id      = var.transit_gateway_id
  tags                    = var.tags
transite_gateway.tf#L8
resource "aws_ec2_transit_gateway_peering_attachment" "example" {
  peer_account_id         = aws_ec2_transit_gateway.peer.owner_id
  peer_region             = data.aws_region.peer.name
  peer_transit_gateway_id = aws_ec2_transit_gateway.peer.id
  transit_gateway_id      = aws_ec2_transit_gateway.local.id

ec2_transit_gateway_peering_attachment_test.tf#L11
resource "aws_ec2_transit_gateway_peering_attachment" "peering" {
  peer_account_id         = "123456789111"
  peer_region             = "eu-west-1"
  peer_transit_gateway_id = "tgw-654321"
  transit_gateway_id      = "tgw-123456"

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 Peering Attachment. For examples of custom route table association and propagation, see the EC2 Transit Gateway Networking Examples Guide.

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::TransitGatewayPeeringAttachment (CloudFormation)

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

Example Usage from GitHub

Seoul.yml#L884
    Type: AWS::EC2::TransitGatewayPeeringAttachment
    Properties:
      PeerAccountId: 675763551292
      PeerRegion: ap-southeast-1
      PeerTransitGatewayId: tgw-0cd7a6a6cde58d24e
      Tags:
Attachment_tgw.yaml#L46
    Type: AWS::EC2::TransitGatewayPeeringAttachment
    Properties:
      PeerAccountId: !Sub '${AWS::AccountId}'
      PeerRegion: !Ref TGWRegion
      PeerTransitGatewayId: !Ref PeerTGWId
      Tags:
template.json#L2707
    "AWS::EC2::TransitGatewayPeeringAttachment": {
      "Type": "AWS::EC2::TransitGatewayPeeringAttachment",
      "Properties": {}
    },
    "AWS::KinesisAnalyticsV2::ApplicationReferenceDataSource": {
      "Type": "AWS::KinesisAnalyticsV2::ApplicationReferenceDataSource",

Parameters

Explanation in CloudFormation Registry

Requests a transit gateway peering attachment between the specified transit gateway (requester) and a peer transit gateway (accepter). The transit gateways must be in different Regions. The peer transit gateway can be in your account or a different AWS account.

After you create the peering attachment, the owner of the accepter transit gateway must accept the attachment request.

Frequently asked questions

What is AWS Amazon EC2 Transit Gateway Peering Attachment?

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

For Terraform, the danielmacuare/aws-net, anjanisone/Vadana-First-Task and plus3it/terraform-aws-tardigrade-transit-gateway source code examples are useful. See the Terraform Example section for further details.

For CloudFormation, the nnany1123/nnany, CameronBeeler/CloudFormation and mhlabs/aws-icons-directory source code examples are useful. See the CloudFormation Example section for further details.