-
-
Notifications
You must be signed in to change notification settings - Fork 87
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 #20
Comments
Unfortunately, you hit a limitation of Terraform which is described here - hashicorp/terraform#4149 The solution is:
|
@antonbabenko thanks, but it is not entirely clear for me why it happens now, because this issue is happening only when I am applying it via pipeline (bitbucket in this case). when I do a plan and apply localy everything works correctly. So it might be an issue of some library version or so? |
This issue was there since the early days of Terraform. The difference you experience can be related to the fact that different environments (on CI and when running locally) starting from different bases. One environment has Lambda function already created and it succeeds. |
@antonbabenko I've applied all lambdas (that are part of the service_intergrations) - also tried to add depends_on statement in the step-functions in order to wait for lambdas to create but still getting the error: on .terraform/modules/state-machine/main.tf line 76, in data "aws_iam_policy_document" "service": The "for_each" value depends on resource attributes that cannot be determined |
Make sure that you apply all resources/modules mentioned in |
I had the same issue. The only workaround I can see here is to:
|
This issue has been automatically marked as stale because it has been open 30 days |
Please keep this issue open. This is a major problem using this module. |
This issue has been resolved in version 2.5.2 🎉 |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
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.
Before you submit an issue, please perform the following first:
.terraform
directory (! ONLY if state is stored remotely, which hopefully you are following that best practice!):rm -rf .terraform/
terraform init
Versions
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.
The text was updated successfully, but these errors were encountered: