-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Erroneous 'Invalid for_each argument' when interpolating const map #22735
Copy link
Copy link
Closed
Description
Terraform Version
0.12.8
Terraform Configuration Files
locals {
server_count = {
location1 = {
type1 = 3
}
}
server_set = toset(flatten([
for loc in keys(local.server_count) : [
for type in keys(local.server_count[loc]) : [
for i in range(local.server_count[loc][type]) : "${loc}_${type}_${i}"
]
]
]))
}
resource "" "" {
for_each = local.server_set
# ...
}Expected Behavior
Successful plan.
Actual Behavior
Error: Invalid for_each argument
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.
Steps to Reproduce
- Config as described
terraform plan
Additional Context
As expected, terraform apply -target=locals.server_set does not help:
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Reactions are currently unavailable