Skip to content

Set ecr_user_enabled to true fail the cold start component apply #18

@goruha

Description

@goruha

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-a

Error 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

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