Resource: aws_vpc_peering_connection

Provides a resource to manage a VPC peering connection.

Example Usage

resource "aws_vpc_peering_connection" "foo" {
  peer_owner_id = var.peer_owner_id
  peer_vpc_id   = aws_vpc.bar.id
  vpc_id        = aws_vpc.foo.id
}

Basic usage with connection options:

resource "aws_vpc_peering_connection" "foo" {
  peer_owner_id = var.peer_owner_id
  peer_vpc_id   = aws_vpc.bar.id
  vpc_id        = aws_vpc.foo.id

  accepter {
    allow_remote_vpc_dns_resolution = true
  }

  requester {
    allow_remote_vpc_dns_resolution = true
  }
}

Basic usage with tags:

resource "aws_vpc_peering_connection" "foo" {
  peer_owner_id = var.peer_owner_id
  peer_vpc_id   = aws_vpc.bar.id
  vpc_id        = aws_vpc.foo.id
  auto_accept   = true

  tags = {
    Name = "VPC Peering between foo and bar"
  }
}

resource "aws_vpc" "foo" {
  cidr_block = "10.1.0.0/16"
}

resource "aws_vpc" "bar" {
  cidr_block = "10.2.0.0/16"
}

Basic usage with region:

resource "aws_vpc_peering_connection" "foo" {
  peer_owner_id = var.peer_owner_id
  peer_vpc_id   = aws_vpc.bar.id
  vpc_id        = aws_vpc.foo.id
  peer_region   = "us-east-1"
}

resource "aws_vpc" "foo" {
  provider   = aws.us-west-2
  cidr_block = "10.1.0.0/16"
}

resource "aws_vpc" "bar" {
  provider   = aws.us-east-1
  cidr_block = "10.2.0.0/16"
}

Argument Reference

This argument supports the following arguments:

Accepter and Requester Arguments

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Notes

If both VPCs are not in the same AWS account and region do not enable the auto_accept attribute. The accepter can manage its side of the connection using the aws_vpc_peering_connection_accepter resource or accept the connection manually using the AWS Management Console, AWS CLI, through SDKs, etc.

Timeouts

Configuration options:

Import

In Terraform v1.5.0 and later, use an import block to import VPC Peering resources using the VPC peering id. For example:

import {
  to = aws_vpc_peering_connection.test_connection
  id = "pcx-111aaa111"
}

Using terraform import, import VPC Peering resources using the VPC peering id. For example:

% terraform import aws_vpc_peering_connection.test_connection pcx-111aaa111