Skip to content

[BUG] For_each cannot be determined until apply #117

@sarasensible

Description

@sarasensible

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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions