generated from cloudposse-terraform-components/template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
bug🐛 An issue with the system🐛 An issue with the system
Description
Describe the Bug
Initial (cold start) deployment of the module with ecr_user_enabled: true lead to failure
Expected Behavior
Should apply smoothly and create ECR repositories and a user
Steps to Reproduce
Deploy the following configuration
components:
terraform:
ecr:
vars:
ecr_user_enabled: true
images:
- microservice-aError message
Error: Invalid for_each argument
│
│ on .terraform/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 : [])
│ ├────────────────
│ │ local.ecr_need_policy is a bool, known only after apply
│ │ local.image_names is list of string with 4 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.
╵
exit status 1
Additional Context
The failure happened because the internal ecr module depends on aws_iam_user.ecr[*].arn that is unknown before applying.
https://github.com/cloudposse-terraform-components/aws-ecr/blob/main/src/main.tf#L22
Metadata
Metadata
Assignees
Labels
bug🐛 An issue with the system🐛 An issue with the system