thomasbiddle / terraform-aws-vpc-peering

A Terraform module to configure a VPC Peering connection in AWS.
https://registry.terraform.io/modules/thomasbiddle/vpc-peering
MIT License
18 stars 16 forks source link

Option to specify the number of route table #3

Open oonisim opened 6 years ago

oonisim commented 6 years ago

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)}" <---
thomasbiddle commented 6 years ago

Thanks for the report - PRs are welcome :-)

davehowell commented 5 years ago

I've seen this working in Terraform 0.12, e.g. https://github.com/grem11n/terraform-aws-vpc-peering/blob/master/main.tf#L70