1. Answers
  2. Managing AWS Transit Gateway Peering Attachments

How do I manage AWS Transit Gateway peering attachments?

In this guide, we will create and manage AWS Transit Gateway peering attachments using Pulumi. A Transit Gateway peering attachment allows you to establish a peering connection between two Transit Gateways in the same or different AWS regions. This setup is useful for enabling communication between VPCs attached to different Transit Gateways.

The following Pulumi program will:

  1. Create two Transit Gateways in different regions.
  2. Establish a peering connection between the two Transit Gateways.
  3. Accept the peering connection request.

Below is the complete code to achieve this:

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Create the first Transit Gateway in the primary region
const transitGateway1 = new aws.ec2transitgateway.TransitGateway("transitGateway1", {
    description: "Primary Transit Gateway",
});

// Create the second Transit Gateway in a different region
const provider = new aws.Provider("provider", { region: "us-west-2" });
const transitGateway2 = new aws.ec2transitgateway.TransitGateway("transitGateway2", {
    description: "Secondary Transit Gateway",
}, { provider });

// Create a peering attachment between the two Transit Gateways
const peeringAttachment = new aws.ec2transitgateway.PeeringAttachment("peeringAttachment", {
    peerRegion: "us-west-2",
    peerTransitGatewayId: transitGateway2.id,
    transitGatewayId: transitGateway1.id,
});

// Accept the peering attachment request
const peeringAttachmentAccepter = new aws.ec2transitgateway.PeeringAttachmentAccepter("peeringAttachmentAccepter", {
    transitGatewayAttachmentId: peeringAttachment.id,
    tags: {
        Name: "Accepted Peering Attachment",
    },
}, { provider });

// Export the Transit Gateway IDs and the peering attachment ID
export const transitGateway1Id = transitGateway1.id;
export const transitGateway2Id = transitGateway2.id;
export const peeringAttachmentId = peeringAttachment.id;

Key Points

  • Transit Gateway: A network transit hub that you can use to interconnect your VPCs and on-premises networks.
  • Peering Attachment: A connection between two Transit Gateways to enable communication between their attached VPCs.
  • Provider: Specifies the AWS region for resources that should be created in a different region.

Summary

In this guide, we created two Transit Gateways in different AWS regions and established a peering connection between them. We also accepted the peering connection request to enable inter-region VPC communication. This setup is useful for building scalable and interconnected network architectures across multiple AWS regions.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up