Skip to content

Commit

Permalink
Allow peering connections to be defined for AWS VPCs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesiarmes committed Jun 11, 2024
1 parent 74ecc60 commit 5997ba2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
38 changes: 38 additions & 0 deletions aws/vpc/peers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
resource "aws_vpc_peering_connection" "peer" {
for_each = var.peers

peer_owner_id = each.value.account_id
peer_vpc_id = each.value.vpc_id
vpc_id = module.vpc.vpc_id
peer_region = each.value.region
}

resource "aws_network_acl_rule" "peer_ingress" {
for_each = var.peers

network_acl_id = module.vpc.private_network_acl_id
rule_number = 200
egress = false
protocol = "-1"
rule_action = "allow"
cidr_block = each.value.cidr
}

resource "aws_network_acl_rule" "peer_egress" {
for_each = var.peers

network_acl_id = module.vpc.private_network_acl_id
rule_number = 300
egress = true
protocol = "-1"
rule_action = "allow"
cidr_block = each.value.cidr
}

resource "aws_route" "peer" {
for_each = var.peers

route_table_id = module.vpc.private_route_table_id
destination_cidr_block = each.value.cidr
vpc_peering_connection_id = aws_vpc_peering_connection.peer[each.key].id
}
10 changes: 10 additions & 0 deletions aws/vpc/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ variable "logging_key_id" {
description = "KMS key ID for encrypting logs."
}

variable "peers" {
type = map(object({
account_id = string
region = string
vpc_id = string
}))

description = "List of VPC peering connections."
}

variable "private_subnets" {
type = list(string)
description = "List of private subnet CIDR blocks."
Expand Down

0 comments on commit 5997ba2

Please sign in to comment.