diff --git a/README.md b/README.md index a49c0f8..9a6ad76 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ module "captain" { | [node\_pool](#module\_node\_pool) | cloudposse/eks-node-group/aws | 2.9.0 | | [subnets](#module\_subnets) | cloudposse/dynamic-subnets/aws | 2.0.4 | | [vpc](#module\_vpc) | cloudposse/vpc/aws | 2.0.0 | +| [vpc\_peering\_accepter\_with\_routes](#module\_vpc\_peering\_accepter\_with\_routes) | ./modules/vpc_peering_accepter_with_routes | n/a | ## Resources @@ -79,6 +80,7 @@ module "captain" { | [eks\_version](#input\_eks\_version) | The version of EKS to deploy | `string` | `"1.26"` | no | | [iam\_role\_to\_assume](#input\_iam\_role\_to\_assume) | The full ARN of the IAM role to assume | `string` | n/a | yes | | [node\_pools](#input\_node\_pools) | node pool configurations:
- name (string): Name of the node pool. MUST BE UNIQUE! Recommended to use YYYYMMDD in the name
- node\_count (number): number of nodes to create in the node pool.
- instance\_type (string): Instance type to use for the nodes. ref: https://instances.vantage.sh/
- ami\_image\_id (string): AMI to use for EKS worker nodes. ref: https://github.com/awslabs/amazon-eks-ami/releases
- spot (bool): Enable spot instances for the nodes. DO NOT ENABLE IN PROD!
- disk\_size\_gb (number): Disk size in GB for the nodes. |
list(object({
name = string
node_count = number
instance_type = string
ami_image_id = string
spot = bool
disk_size_gb = number
}))
|
[
{
"ami_image_id": "amazon-eks-node-1.24-v20230406",
"disk_size_gb": 20,
"instance_type": "t3a.large",
"name": "default-pool",
"node_count": 1,
"spot": false
}
]
| no | +| [peering\_configs](#input\_peering\_configs) | A list of maps containing VPC peering configuration details |
list(object({
vpc_peering_connection_id = string
destination_cidr_block = string
}))
| `[]` | no | | [region](#input\_region) | The AWS region to deploy into | `string` | n/a | yes | | [vpc\_cidr\_block](#input\_vpc\_cidr\_block) | The CIDR block for the VPC | `string` | `"10.65.0.0/16"` | no | diff --git a/modules/vpc_peering_accepter_with_routes/main.tf b/modules/vpc_peering_accepter_with_routes/main.tf new file mode 100644 index 0000000..8643526 --- /dev/null +++ b/modules/vpc_peering_accepter_with_routes/main.tf @@ -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 +} + diff --git a/peering.tf b/peering.tf new file mode 100644 index 0000000..9713f35 --- /dev/null +++ b/peering.tf @@ -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 +} diff --git a/variables.tf b/variables.tf index dad394a..73cd6dd 100644 --- a/variables.tf +++ b/variables.tf @@ -61,6 +61,15 @@ variable "iam_role_to_assume" { description = "The full ARN of the IAM role to assume" } +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 = [] +} + locals { vpc = { cidr_block = var.vpc_cidr_block