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

Error: Invalid for_each argument #119

Open
hans-d opened this issue Feb 15, 2024 · 1 comment
Open

Error: Invalid for_each argument #119

hans-d opened this issue Feb 15, 2024 · 1 comment
Labels
bug 🐛 An issue with the system

Comments

@hans-d
Copy link

hans-d commented Feb 15, 2024

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

@hans-d hans-d added the bug 🐛 An issue with the system label Feb 15, 2024
@hans-d
Copy link
Author

hans-d commented Feb 15, 2024

in 0.36 as well

│   on ecr/modules/ecr/main.tf line 233, in resource "aws_ecr_repository_policy" "name":
│  233:   for_each   = toset(local.ecr_need_policy && module.this.enabled ? local.image_names : [])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue with the system
Projects
None yet
Development

No branches or pull requests

1 participant