AWS Amazon EC2 Peering Connection

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


Fix issues in your cloud & app configurations

Test for misconfigurations of this resource in your cloud.


Terraform Example (aws_vpc_peering_connection)

Provides a resource to manage a VPC peering connection.

NOTE on VPC Peering Connections and VPC Peering Connection Options: Terraform provides both a standalone VPC Peering Connection Options and a VPC Peering Connection resource with accepter and requester attributes. Do not manage options for the same VPC peering connection in both a VPC Peering Connection resource and a VPC Peering Connection Options resource. Doing so will cause a conflict of options and will overwrite the options. Using a VPC Peering Connection Options resource decouples management of the connection options from management of the VPC Peering Connection and allows options to be set correctly in cross-account scenarios. -> Note: For cross-account (requester's AWS account differs from the accepter's AWS account) or inter-region VPC Peering Connections use the aws_vpc_peering_connection resource to manage the requester's side of the connection and use the aws_vpc_peering_connection_accepter resource to manage the accepter's side of the connection.


Example Usage (from GitHub)

resource "aws_vpc_peering_connection" "us-east-1-us-east-2" {
provider =
vpc_id =
peer_vpc_id =
peer_region = "us-east-2"
resource "aws_vpc_peering_connection" "cyhy_bod_peering_connection" {
  vpc_id      =
  peer_vpc_id =
  auto_accept = true

  tags = merge(

CloudFormation Example (AWS::EC2::VPCPeeringConnection)

Requests a VPC peering connection between two VPCs: a requester VPC that you own and an accepter VPC with which to create the connection. The accepter VPC can belong to another AWS account and can be in a different Region to the requester VPC.

The requester VPC and accepter VPC cannot have overlapping CIDR blocks. If you create a VPC peering connection request between VPCs with overlapping CIDR blocks, the VPC peering connection has a status of failed.

For more information, see Walkthough: Peer with a VPC in another AWS account.


Frequently asked questions

What is AWS Amazon EC2 Peering Connection?

AWS Amazon EC2 Peering Connection 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 Peering Connection?

For Terraform, the huanwlisa/terraform and cisagov/cyhy_amis source code examples are useful. See the Terraform Example section for further details.