terraform-aws-vpc-peering icon indicating copy to clipboard operation
terraform-aws-vpc-peering copied to clipboard

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

Open ryan-gontarek opened this issue 4 years ago • 6 comments

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.

ryan-gontarek avatar Feb 28 '20 18:02 ryan-gontarek

@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

grem11n avatar Mar 02 '20 20:03 grem11n

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.

ryan-gontarek avatar Mar 04 '20 14:03 ryan-gontarek

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

ivanmartos avatar Aug 18 '20 10:08 ivanmartos

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?

bmcustodio avatar May 04 '21 15:05 bmcustodio

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

grem11n avatar May 04 '21 19:05 grem11n

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"

pj0620 avatar Sep 07 '21 16:09 pj0620

Closing old issues.

grem11n avatar Apr 11 '23 09:04 grem11n