Skip to content

Resource: awsEc2TransitGatewayPeeringAttachment

Manages an EC2 Transit Gateway Peering Attachment. For examples of custom route table association and propagation, see the EC2 Transit Gateway Networking Examples Guide.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsLocal = new aws.provider.AwsProvider(this, "aws", {
  alias: "local",
  region: "us-east-1",
});
const awsPeer = new aws.provider.AwsProvider(this, "aws_1", {
  alias: "peer",
  region: "us-west-2",
});
const awsEc2TransitGatewayLocal = new aws.ec2TransitGateway.Ec2TransitGateway(
  this,
  "local",
  {
    provider: `\${${awsLocal.fqn}}`,
    tags: {
      Name: "Local TGW",
    },
  }
);
const awsEc2TransitGatewayPeer = new aws.ec2TransitGateway.Ec2TransitGateway(
  this,
  "peer",
  {
    provider: `\${${awsPeer.fqn}}`,
    tags: {
      Name: "Peer TGW",
    },
  }
);
const dataAwsRegionPeer = new aws.dataAwsRegion.DataAwsRegion(this, "peer_4", {
  provider: `\${${awsPeer.fqn}}`,
});
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
dataAwsRegionPeer.overrideLogicalId("peer");
new aws.ec2TransitGatewayPeeringAttachment.Ec2TransitGatewayPeeringAttachment(
  this,
  "example",
  {
    peerAccountId: awsEc2TransitGatewayPeer.ownerId,
    peerRegion: dataAwsRegionPeer.name,
    peerTransitGatewayId: awsEc2TransitGatewayPeer.id,
    tags: {
      Name: "TGW Peering Requestor",
    },
    transitGatewayId: awsEc2TransitGatewayLocal.id,
  }
);

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 awsEc2TransitGatewayPeeringAttachment resource can be found in the /examples/transitGatewayCrossAccountPeeringAttachment directory within the Github Repository.

Argument Reference

The following arguments are supported:

  • peerAccountId - (Optional) Account ID of EC2 Transit Gateway to peer with. Defaults to the account ID the AWS provider is currently connected to.
  • peerRegion - (Required) Region of EC2 Transit Gateway to peer with.
  • peerTransitGatewayId - (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 defaultTags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
  • transitGatewayId - (Required) Identifier of EC2 Transit Gateway.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • id - EC2 Transit Gateway Attachment identifier
  • tagsAll - A map of tags assigned to the resource, including those inherited from the provider defaultTags configuration block.

Import

awsEc2TransitGatewayPeeringAttachment can be imported by using the EC2 Transit Gateway Attachment identifier, e.g.,

terraform import aws_ec2_transit_gateway_peering_attachment.example tgw-attach-12345678