grem11n / terraform-aws-vpc-peering

Terraform module to setup VPC peering connection
https://registry.terraform.io/modules/grem11n/vpc-peering/aws/latest
Apache License 2.0
126 stars 91 forks source link

Migrating from tf11 to tf12 count = length(data.aws_route_tables.this_vpc_rts.ids) issue #49

Closed ryan-gontarek closed 1 year ago

ryan-gontarek commented 4 years ago

Migrating from tf11 (v1.3.1) to tf12 (v2.0.0) with this module and running into this issue:

Error: Invalid count argument count = length(data.aws_route_tables.this_vpc_rts.ids) The "count" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work around this, use the -target argument to first apply only the resources that the count depends on.

I'm migrating existing infrastructure so I'm confused why I'm getting an error about not knowing the value of count (the infrastructure already exists). During the tf11 to tf12 infrastructure migration, none of the underlying resources should be changing.

I'm also targeting the vpc that creates the vpc peering connections and when I run terraform12.20 apply -target=module.vpc, I get the same count error from above. Any help/advice is appreciated.

grem11n commented 4 years ago

@rgontarek, thank you for reporting this. I will try to reproduce it in my test environment. For now, my best guess is that after the migration output changed its name somehow. Need to look closer at this topic

ryan-gontarek commented 4 years ago

It appears that in terraform12 the code defaults to sorting the data.aws_route_tables.this_vpc_rts.ids but in terraform11 the data.aws_route_tables.this_vpc_rts.ids is not sorted by default. As a result all the routes all want to be changed and the length(data.aws_route_tables.this_vpc_rts.ids) needs to be recalculated.

But in addition to the recalculation needing to be done, terraform is also erroring in regards to the route table ids not being known prior to apply so relying on them for count is no longer working.

ivanmartos commented 4 years ago

I had the same issue. I resolved it by following (with downtime)

  1. on terraform v 0.11.4 and module v1.3.1 delete the module
  2. migrate to terraform 0.12.29
  3. add module v2.2.3
  4. terraform apply
bmcustodio commented 3 years ago

I'm facing the same issue with Terraform 0.15.1 and version 4.0.0 of the module. Are there any news regarding this?

grem11n commented 3 years ago

Please, try to provide route tables IDs explicitly as in the depends on example: https://github.com/grem11n/terraform-aws-vpc-peering/blob/master/examples/module-depends-on/README.md

You can also use depends_on functionality, if you're on Terraform >=0.13

pj0620 commented 3 years ago

I fixed this issue by, as noted in the error message, using the -target argument. You are using it in apply it should be used in plan.

terraform plan -target="module.vpc"

grem11n commented 1 year ago

Closing old issues.