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

[BUG] For_each cannot be determined until apply #117

Open
sarasensible opened this issue Jun 21, 2024 · 1 comment
Open

[BUG] For_each cannot be determined until apply #117

sarasensible opened this issue Jun 21, 2024 · 1 comment
Assignees
Labels

Comments

@sarasensible
Copy link

sarasensible commented Jun 21, 2024

Describe the bug
Similar to #102 , a plan using 7.0.0 of the module results in a for_each invalid argument error. I am using the single account multi-region module.

Terraform version: What Terraform version do you use?
1.7.5

Module version: What module version do you use?
7.0.0

Error message:

│ Error: Invalid for_each argument
│ 
│   on .terraform/modules/single_account_multi_region/data.tf line 61, in data "aws_route_tables" "this_associated_route_tables":
│   61:   for_each = { for subnet in data.aws_subnets.this.ids : subnet => subnet }
│     ├────────────────
│     │ data.aws_subnets.this.ids is a list of string, known only after apply
│ 
│ The "for_each" 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 for_each depends on.
╵
╷
│ Error: Invalid for_each argument
│ 
│   on .terraform/modules/single_account_multi_region/data.tf line 94, in data "aws_route_tables" "peer_associated_route_tables":
│   94:   for_each = { for subnet in data.aws_subnets.peer.ids : subnet => subnet }
│     ├────────────────
│     │ data.aws_subnets.peer.ids is a list of string, known only after apply
│ 
│ The "for_each" 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 for_each depends on.

Terraform code that produces the error:

module "single_account_multi_region" {
  source  = "grem11n/vpc-peering/aws"
  version = "7.0.0"

  depends_on = [module.vpc]

  providers = {
    aws.this = aws
    aws.peer = aws.us-east-2
  }

  this_vpc_id = module.vpc.vpc_id
  peer_vpc_id = data.aws_vpcs.main_us_east_2.ids[0]

  auto_accept_peering = true
  this_rts_ids = module.vpc.private_route_table_ids
  peer_rts_ids = data.aws_route_tables.private_rts.ids

Additional context
Workaround is to downgrade to 6.0.0

@yannverreault
Copy link

yannverreault commented Jul 26, 2024

I believe this bug has been introduced by #109 . We are facing the same issue where we try to initiate a new environment. My guess is the VPC and subnets aren't created yet so the values in the for_each can't be determined until apply.

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

No branches or pull requests

3 participants