Provides a resource to manage a VPC peering connection.
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"
}
This argument supports the following arguments:
peer_owner_id
- (Optional) The AWS account ID of the target peer VPC.
Defaults to the account ID the AWS provider is currently connected to, so must be managed if connecting cross-account.peer_vpc_id
- (Required) The ID of the target VPC with which you are creating the VPC Peering Connection.vpc_id
- (Required) The ID of the requester VPC.auto_accept
- (Optional) Accept the peering (both VPCs need to be in the same AWS account and region).peer_region
- (Optional) The region of the accepter VPC of the VPC Peering Connection. auto_accept
must be false
,
and use the aws_vpc_peering_connection_accepter
to manage the accepter side.accepter
(Optional) - An optional configuration block that allows for VPC Peering Connection options to be set for the VPC that accepts
the peering connection (a maximum of one).requester
(Optional) - A optional configuration block that allows for VPC Peering Connection options to be set for the VPC that requests
the peering connection (a maximum of one).tags
- (Optional) A map of tags to assign to the resource. If configured with a provider default_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level.allow_remote_vpc_dns_resolution
- (Optional) Allow a local VPC to resolve public DNS hostnames to
private IP addresses when queried from instances in the peer VPC.This resource exports the following attributes in addition to the arguments above:
id
- The ID of the VPC Peering Connection.accept_status
- The status of the VPC Peering Connection request.tags_all
- A map of tags assigned to the resource, including those inherited from the provider default_tags
configuration block.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.
create
- (Default 1m
)update
- (Default 1m
)delete
- (Default 1m
)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