terraform-aws-vpc-peering
terraform-aws-vpc-peering copied to clipboard
Migrating from tf11 to tf12 count = length(data.aws_route_tables.this_vpc_rts.ids) issue
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.
@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
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.
I had the same issue. I resolved it by following (with downtime)
- on terraform v
0.11.4
and modulev1.3.1
delete the module - migrate to terraform
0.12.29
- add module
v2.2.3
- terraform apply
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?
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
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"
Closing old issues.