Skip to content

Error: Invalid for_each argument #119

@hans-d

Description

@hans-d

Describe the Bug

╷
│ Error: Invalid for_each argument
│
│   on  ecr/modules/ecr/main.tf line 310, in resource "aws_ecr_repository_policy" "name":
│  310:   for_each   = toset(local.ecr_need_policy && module.this.enabled ? local.image_names : [])
│     ├────────────────
│     │ local.ecr_need_policy is a bool, known only after apply
│     │ local.image_names is list of string with 2 elements
│     │ module.this.enabled is true
│
│ The "for_each" set includes values derived from resource attributes that cannot be determined until apply, and so Terraform cannot determine the full set of keys that will identify the instances of this resource.
│
│ When working with unknown values in for_each, it's better to use a map value where the keys are defined statically in your configuration and where only the values contain apply-time results.
│
│ Alternatively, you could use the -target planning option to first apply only the resources that the for_each value depends on, and then apply a second time to fully converge.
╵

Expected Behavior

no issues

Steps to Reproduce

fresh deployment using ecr, using

module "ecr" {
  source  = "cloudposse/ecr/aws"
  version = "0.40.0"
}

Screenshots

No response

Environment

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug🐛 An issue with the system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions