Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The count fails in resource "aws_route" "requestor" #19

Open
mordax7 opened this issue Jun 30, 2020 · 5 comments
Open

The count fails in resource "aws_route" "requestor" #19

mordax7 opened this issue Jun 30, 2020 · 5 comments

Comments

@mordax7
Copy link

mordax7 commented Jun 30, 2020

The Terraform AWS VPC Peering module fails if the requestor VPC does not exist yet.
We are trying to create the requestor's VPC and the peering at the same time, which ends up in this error:

Error: Invalid count argument

  on .terraform/modules/vpc.vpc_peering/main.tf line 62, in resource "aws_route" "requestor":
  62:   count                     = var.enabled ? length(distinct(sort(data.aws_route_tables.requestor.0.ids))) * length(data.aws_vpc.acceptor.0.cidr_block_associations) : 0

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.


Error: Invalid count argument

  on .terraform/modules/vpc.vpc_peering/main.tf line 71, in resource "aws_route" "acceptor":
  71:   count                     = var.enabled ? length(distinct(sort(data.aws_route_tables.acceptor.0.ids))) * length(data.aws_vpc.requestor.0.cidr_block_associations) : 0

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.
@gowthamakanthan
Copy link

gowthamakanthan commented Mar 4, 2021

Facing the same issue. Is this fixed? Am using the following versions.

Terraform v0.12.29
+ provider.aws v3.1.0
+ provider.template v2.1.2

@hanselke
Copy link

have the same problem

@ekristen
Copy link

I am seeing the same but I am not sure there's anyway around it with the way the module is written, it's a limitation of terraform. One possible way to address this would be to have a version where you could pass all the route tables from the subnet modules in vs having it discover, terraform would be able to know then what route tables were going to exist at plan time.

@pj0620
Copy link

pj0620 commented Sep 7, 2021

I fixed this issue by, as noted in the error message, using the -target argument.

terraform plan -target="module.vpc"

@mordax7

@mohnishbasha
Copy link

+1, the module.vpc_peering expects both requestor and acceptor vpcs to be provisioned before calling itself.
Is it kinda annoying but you will need to provision them first using the -target= construct and then run terraform again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants