Skip to content
GitHubXDiscord

TransitGatewayVpcAttachment

The TransitGatewayVpcAttachment resource allows you to manage VPC attachments to an AWS Transit Gateway. This resource facilitates the connection of multiple VPCs to a single transit gateway, enabling easier network management and routing. For more details, refer to the AWS EC2 TransitGatewayVpcAttachments documentation.

Create a basic Transit Gateway VPC attachment with required properties and a common optional tag.

import AWS from "alchemy/aws/control";
const transitGatewayVpcAttachment = await AWS.EC2.TransitGatewayVpcAttachment("myVpcAttachment", {
TransitGatewayId: "tgw-0abcd1234efgh5678",
VpcId: "vpc-12345678",
SubnetIds: [
"subnet-12345678",
"subnet-87654321"
],
Tags: [
{
Key: "Name",
Value: "My VPC Attachment"
}
]
});

Configure a Transit Gateway VPC attachment with additional subnets and specific options.

const advancedTransitGatewayVpcAttachment = await AWS.EC2.TransitGatewayVpcAttachment("advancedVpcAttachment", {
TransitGatewayId: "tgw-0abcd1234efgh5678",
VpcId: "vpc-12345678",
SubnetIds: [
"subnet-12345678",
"subnet-87654321"
],
AddSubnetIds: [
"subnet-13572468"
],
RemoveSubnetIds: [
"subnet-87654321"
],
Options: {
ApplianceMode: "enable"
}
});

If a Transit Gateway VPC attachment already exists, you can adopt it instead of failing.

const adoptedTransitGatewayVpcAttachment = await AWS.EC2.TransitGatewayVpcAttachment("adoptedVpcAttachment", {
TransitGatewayId: "tgw-0abcd1234efgh5678",
VpcId: "vpc-12345678",
SubnetIds: [
"subnet-12345678",
"subnet-87654321"
],
adopt: true
});

Create a Transit Gateway VPC attachment with multiple tags for better organization and management.

const taggedTransitGatewayVpcAttachment = await AWS.EC2.TransitGatewayVpcAttachment("taggedVpcAttachment", {
TransitGatewayId: "tgw-0abcd1234efgh5678",
VpcId: "vpc-12345678",
SubnetIds: [
"subnet-12345678",
"subnet-87654321"
],
Tags: [
{
Key: "Environment",
Value: "Production"
},
{
Key: "Project",
Value: "Project X"
}
]
});