Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions terraform-modules/aws/vpc-peering/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## Requirements

No requirements.

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [aws_route_table_association.association](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table_association) | resource |
| [aws_vpc_endpoint_route_table_association.endpoint_association](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_endpoint_route_table_association) | resource |
| [aws_vpc_peering_connection.peering_connection](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_peering_connection) | resource |
| [aws_route_table.route_table](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route_table) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_accepter_allow_remote_vpc_dns_resolution"></a> [accepter\_allow\_remote\_vpc\_dns\_resolution](#input\_accepter\_allow\_remote\_vpc\_dns\_resolution) | Specifies whether DNS resolution is enabled for the VPC peering connection | `bool` | `true` | no |
| <a name="input_auto_accept"></a> [auto\_accept](#input\_auto\_accept) | Specifies whether the peering connection should be automatically accepted | `bool` | `true` | no |
| <a name="input_peer_vpc_id"></a> [peer\_vpc\_id](#input\_peer\_vpc\_id) | The ID of the VPC with which you are creating the VPC Peering Connection. | `string` | n/a | yes |
| <a name="input_requester_allow_remote_vpc_dns_resolution"></a> [requester\_allow\_remote\_vpc\_dns\_resolution](#input\_requester\_allow\_remote\_vpc\_dns\_resolution) | Specifies whether DNS resolution is enabled for the VPC peering connection | `bool` | `true` | no |
| <a name="input_subnet_ids"></a> [subnet\_ids](#input\_subnet\_ids) | A list of subnet IDs for which to retrieve the associated route tables | `list(string)` | n/a | yes |
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to apply to the VPC peering connection | `map(any)` | `{}` | no |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The ID of the VPC in which the subnets are located | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_aws_route_table_association_id"></a> [aws\_route\_table\_association\_id](#output\_aws\_route\_table\_association\_id) | The ID of the association |
| <a name="output_aws_vpc_endpoint_route_table_association_id"></a> [aws\_vpc\_endpoint\_route\_table\_association\_id](#output\_aws\_vpc\_endpoint\_route\_table\_association\_id) | A hash of the EC2 Route Table and VPC Endpoint identifiers. |
| <a name="output_vpc_peering_connection_accept_status"></a> [vpc\_peering\_connection\_accept\_status](#output\_vpc\_peering\_connection\_accept\_status) | The status of the VPC Peering Connection request |
| <a name="output_vpc_peering_connection_id"></a> [vpc\_peering\_connection\_id](#output\_vpc\_peering\_connection\_id) | The ID of the VPC Peering Connection |
36 changes: 36 additions & 0 deletions terraform-modules/aws/vpc-peering/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Create peering connection between VPC A and VPC B
resource "aws_vpc_peering_connection" "peering_connection" {
vpc_id = var.vpc_id
peer_vpc_id = var.peer_vpc_id
auto_accept = var.auto_accept

accepter {
allow_remote_vpc_dns_resolution = var.accepter_allow_remote_vpc_dns_resolution
}

requester {
allow_remote_vpc_dns_resolution = var.requester_allow_remote_vpc_dns_resolution
}
tags = var.tags
}

data "aws_route_table" "route_table" {
for_each = { for id in var.subnet_ids : id => id }
subnet_id = each.value
vpc_id = var.vpc_id
}

# Assign route table to corresponding subnets in VPC B
resource "aws_route_table_association" "association" {
for_each = { for id in var.subnet_ids : id => id }
subnet_id = each.value
route_table_id = data.aws_route_table.route_table[each.key].id
}

# Create endpoint access policy for VPC B
resource "aws_vpc_endpoint_route_table_association" "endpoint_association" {
for_each = { for id in var.subnet_ids : id => id }
vpc_endpoint_id = var.vpc_endpoint_id
route_table_id = data.aws_route_table.route_table[each.key].id
}

9 changes: 9 additions & 0 deletions terraform-modules/aws/vpc-peering/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "vpc_peering_connection_id" {
description = "The ID of the VPC Peering Connection"
value = aws_vpc_peering_connection.peering_connection.id
}

output "vpc_peering_connection_accept_status" {
description = "The status of the VPC Peering Connection request"
value = aws_vpc_peering_connection.peering_connection.accept_status
}
43 changes: 43 additions & 0 deletions terraform-modules/aws/vpc-peering/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
variable "vpc_id" {
type = string
description = "The ID of the VPC in which the subnets are located"
}

variable "peer_vpc_id" {
description = "The ID of the VPC with which you are creating the VPC Peering Connection."
type = string
}

variable "auto_accept" {
description = "Specifies whether the peering connection should be automatically accepted"
type = bool
default = true
}

variable "accepter_allow_remote_vpc_dns_resolution" {
description = "Specifies whether DNS resolution is enabled for the VPC peering connection"
type = bool
default = true
}

variable "requester_allow_remote_vpc_dns_resolution" {
description = "Specifies whether DNS resolution is enabled for the VPC peering connection"
type = bool
default = true
}

variable "subnet_ids" {
type = list(string)
description = "A list of subnet IDs for which to retrieve the associated route tables"
}

variable "vpc_endpoint_id" {
type = string
description = "VPC endpoint Id where you want to point"
}

variable "tags" {
description = "A map of tags to apply to the VPC peering connection"
type = map(any)
default = {}
}