Skip to content

Error: Invalid for_each argument #20

Closed
@mliner

Description

@mliner

Description

Hey, I am using the step-functions module in my application and I am having this issue:

│ Error: Invalid for_each argument │ │ on .terraform/modules/state-machine/main.tf line 76, in data "aws_iam_policy_document" "service": │ 76: for_each = local.create_role && var.attach_policies_for_integrations ? try(tomap(var.service_integrations), var.service_integrations) : tomap({}) │ ├──────────────── │ │ local.create_role is true │ │ var.attach_policies_for_integrations is true │ │ var.service_integrations is object with 2 attributes │ │ 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. ╵

I am not entirely sure why this happens because I am using only standard available service integrations.

⚠️ Note

Before you submit an issue, please perform the following first:

  1. Remove the local .terraform directory (! ONLY if state is stored remotely, which hopefully you are following that best practice!): rm -rf .terraform/
  2. Re-initialize the project root to pull down modules: terraform init
  3. Re-attempt your terraform plan or apply and check if the issue still persists

Versions

  • Terraform: ~>0.14
  • Provider(s): aws - v3.44.0
  • Module: 2.3.0

Code Snippet to Reproduce

` service_integrations = {
lambda = {
lambda = [
module.lambda1.lambda_arn,
module.lambda2.lambda_arn,
module.lambda3.lambda_arn
]
}
ecs_Sync = {
ecs = [module.fargate.task_definition_arn]
events = ["arn:aws:events:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:rule/StepFunctionsGetEventsForECSTaskRule"]
}
}

attach_policy_json = true
policy_json = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "iam:PassRole",
"Resource": "*",
"Effect": "Allow",
"Sid": ""
}
]
}
POLICY`

Actual behavior

Failing on:
╷ │ Error: Invalid for_each argument │ │ on .terraform/modules/state-machine/main.tf line 76, in data "aws_iam_policy_document" "service": │ 76: for_each = local.create_role && var.attach_policies_for_integrations ? try(tomap(var.service_integrations), var.service_integrations) : tomap({}) │ ├──────────────── │ │ local.create_role is true │ │ var.attach_policies_for_integrations is true │ │ var.service_integrations is object with 2 attributes │ │ 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions