Manages an EC2 Transit Gateway Peering Attachment. For examples of custom route table association and propagation, see the EC2 Transit Gateway Networking Examples Guide.
provider "aws" {
alias = "local"
region = "us-east-1"
}
provider "aws" {
alias = "peer"
region = "us-west-2"
}
data "aws_region" "peer" {
provider = aws.peer
}
resource "aws_ec2_transit_gateway" "local" {
provider = aws.local
tags = {
Name = "Local TGW"
}
}
resource "aws_ec2_transit_gateway" "peer" {
provider = aws.peer
tags = {
Name = "Peer TGW"
}
}
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
tags = {
Name = "TGW Peering Requestor"
}
}
A full example of how to create a Transit Gateway in one AWS account, share it with a second AWS account, and attach a to a Transit Gateway in the second account via the aws_ec2_transit_gateway_peering_attachment
resource can be found in the ./examples/transit-gateway-cross-account-peering-attachment
directory within the Github Repository.
This resource supports the following arguments:
peer_account_id
- (Optional) Account ID of EC2 Transit Gateway to peer with. Defaults to the account ID the AWS provider is currently connected to.peer_region
- (Required) Region of EC2 Transit Gateway to peer with.peer_transit_gateway_id
- (Required) Identifier of EC2 Transit Gateway to peer with.tags
- (Optional) Key-value tags for the EC2 Transit Gateway Peering Attachment. If configured with a provider default_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level.transit_gateway_id
- (Required) Identifier of EC2 Transit Gateway.This resource exports the following attributes in addition to the arguments above:
id
- EC2 Transit Gateway Attachment identifiertags_all
- A map of tags assigned to the resource, including those inherited from the provider default_tags
configuration block.In Terraform v1.5.0 and later, use an import
block to import aws_ec2_transit_gateway_peering_attachment
using the EC2 Transit Gateway Attachment identifier. For example:
import {
to = aws_ec2_transit_gateway_peering_attachment.example
id = "tgw-attach-12345678"
}
Using terraform import
, import aws_ec2_transit_gateway_peering_attachment
using the EC2 Transit Gateway Attachment identifier. For example:
% terraform import aws_ec2_transit_gateway_peering_attachment.example tgw-attach-12345678