terraform-aws-vpc-peering
terraform-aws-vpc-peering copied to clipboard
Option to specify the number of route table
Request
Enhancement to be able to use with Terraform registry AWS VPC
Possible change could be adding module values to specify the number of route tables to update. Or please suggest a work around to avoid the issue (below).
module "vpc-peering" {
source = "thomasbiddle/vpc-peering/aws"
peer_from_vpc_name = "vpc_ms"
peer_to_vpc_name = "vpc_ds"
peer_from_vpc_id = "${module.vpc_ms.vpc_id}"
peer_to_vpc_id = "${module.vpc_ds.vpc_id}"
peer_from_route_tables = [ "${module.vpc_ms.private_route_table_ids}" ]
peer_from_route_tables_count = 1 <---
peer_to_route_tables = [ "${module.vpc_ds.intra_route_table_ids}" ]
peer_to_route_tables_count = 1 <---
}
Background
Terraform has a limitation of #10857 not being able to run length() on a computed value.
This (error) is the correct behavior not because you're passing in a list, but because you're performing a function call length on a computed value.
Due to the limitation, the VPC peering module causes an error when used with AWS VPC module passing the route table resource yet to be created.
For example:
module "vpc-peering" {
source = "thomasbiddle/vpc-peering/aws"
peer_from_vpc_name = "vpc_ms"
peer_to_vpc_name = "vpc_ds"
peer_from_vpc_id = "${module.vpc_ms.vpc_id}"
peer_to_vpc_id = "${module.vpc_ds.vpc_id}"
# Causes errors when length() is applied as the private_route_table_ids is yet to be created (calculated)
peer_from_route_tables = [ "${module.vpc_ms.private_route_table_ids}" ]
peer_to_route_tables = [ "${module.vpc_ds.intra_route_table_ids}" ]
}
The error occurs in aws_route.tf to get the number of route tables to update.
resource "aws_route" "peer_from_to_peer_to" {
count = "${length(var.peer_from_route_tables)}" <---