-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: working vpc peering --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a569fee
commit a2cb0f9
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
variable "peering_configs" { | ||
description = "A list of maps containing VPC peering configuration details" | ||
type = list(object({ | ||
vpc_peering_connection_id = string | ||
destination_cidr_block = string | ||
})) | ||
default = [] | ||
} | ||
|
||
variable "route_table_ids" { | ||
description = "A list of route table ids" | ||
type = list(string) | ||
} | ||
|
||
locals { | ||
peering_configs_map = { | ||
for pc in var.peering_configs : | ||
pc.vpc_peering_connection_id => pc | ||
} | ||
} | ||
|
||
resource "aws_vpc_peering_connection_accepter" "accepter" { | ||
for_each = local.peering_configs_map | ||
|
||
vpc_peering_connection_id = each.key | ||
auto_accept = true | ||
} | ||
|
||
locals { | ||
peering_routes = flatten([ | ||
for pc in var.peering_configs : [ | ||
for rt_id in var.route_table_ids : { | ||
vpc_peering_connection_id = pc.vpc_peering_connection_id | ||
destination_cidr_block = pc.destination_cidr_block | ||
route_table_id = rt_id | ||
} | ||
] | ||
]) | ||
} | ||
|
||
resource "aws_route" "peering_routes" { | ||
for_each = { | ||
for pr in local.peering_routes : | ||
"${pr.vpc_peering_connection_id}-${pr.route_table_id}" => pr | ||
} | ||
|
||
route_table_id = each.value.route_table_id | ||
destination_cidr_block = each.value.destination_cidr_block | ||
vpc_peering_connection_id = each.value.vpc_peering_connection_id | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
|
||
|
||
module "vpc_peering_accepter_with_routes" { | ||
source = "./modules/vpc_peering_accepter_with_routes" | ||
route_table_ids = concat(module.subnets.private_route_table_ids, module.subnets.public_route_table_ids) | ||
peering_configs = var.peering_configs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters