This example demonstrates a complete VPC peering setup with automatic route management and DNS resolution using the connections map pattern.
- VPC peering connection with:
- Automatic route creation
- DNS resolution enabled
- Route table management
Configure the peering connection using the connections map:
connections = {
"app-to-data" = {
requester_vpc_id = var.requester_vpc_id
accepter_vpc_id = var.accepter_vpc_id
requester_route_table_ids = var.requester_route_table_ids
accepter_route_table_ids = var.accepter_route_table_ids
requester_destination_cidrs = var.requester_destination_cidrs
accepter_destination_cidrs = var.accepter_destination_cidrs
allow_remote_vpc_dns_resolution = true
}
}- Route Management: Automatically creates routes in specified route tables
- DNS Resolution: Enables DNS resolution across peered VPCs
- Complete Connectivity: Full bidirectional communication setup
terraform init
terraform plan
terraform applyThe module automatically:
- Creates peering connection between VPCs
- Adds routes to specified route tables
- Enables DNS resolution for both VPCs
- Configures bidirectional connectivity
- Routes are created in the specified route tables
- Routes point to the peering connection
- Supports multiple destination CIDRs per VPC
- Instances in requester VPC can resolve DNS names in accepter VPC
- Instances in accepter VPC can resolve DNS names in requester VPC
After successful deployment:
peering_connection_ids = {
"app-to-data" = "pcx-1234567890abcdef0"
}
peering_connection_status = {
"app-to-data" = "active"
}terraform destroy| Name | Version |
|---|---|
| terraform | >= 1.5 |
| aws | >= 5.0 |
No providers.
| Name | Source | Version |
|---|---|---|
| tags | sourcefuse/arc-tags/aws | 1.2.6 |
| vpc_peering | ../../ | n/a |
No resources.
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| accepter_destination_cidrs | List of CIDR blocks to route from accepter VPC (usually requester VPC CIDRs) | list(string) |
n/a | yes |
| accepter_route_table_ids | List of route table IDs in the accepter VPC | list(string) |
n/a | yes |
| accepter_vpc_id | ID of the accepter VPC | string |
n/a | yes |
| aws_region | AWS region | string |
"us-east-1" |
no |
| requester_destination_cidrs | List of CIDR blocks to route from requester VPC (usually accepter VPC CIDRs) | list(string) |
n/a | yes |
| requester_route_table_ids | List of route table IDs in the requester VPC | list(string) |
n/a | yes |
| requester_vpc_id | ID of the requester VPC | string |
n/a | yes |
| Name | Description |
|---|---|
| peering_connection_id | The ID of the VPC peering connection |
| peering_status | The status of the VPC peering connection |