Terraform: 0.12.6 Crashes when resource for_each given a list

Created on 2 Aug 2019  ยท  4Comments  ยท  Source: hashicorp/terraform

Terraform Version

Terraform v0.12.6
+ provider.null v2.1.2

Terraform Configuration Files

locals {
  i = ["t", "g", "f"]
}

data "null_data_source" "test" {
  for_each = local.i

  inputs = {
    value = each.value
  }
}

Crash Output

https://gist.github.com/dpiddockcmp/25d0622a732b41ae704e2bcd9132f895

Expected Behavior

Either:

  • failure message due to resource for_each not supporting lists
  • resources created with the inherent ordering issues of lists ;)

Actual Behavior

Crash. panic: not a string

Steps to Reproduce

  1. terraform init
  2. terraform plan

References

  • Possible duplicate of #22284 ?
bug crash

All 4 comments

Thanks for the bug report. I'm pleased to say that this is fixed by https://github.com/hashicorp/terraform/pull/22279, and the new error you'll get is:

$ terraform plan

Error: Invalid for_each argument

  on main.tf line 6, in data "null_data_source" "test":
   6:   for_each = local.i

The given "for_each" argument value is unsuitable: the "for_each" argument
must be a map, or set of strings, and you have provided a value of type tuple.

This fix will be deployed in Terraform v0.12.7.

Not sure why this issue is closed. #22279 doesn't actually fix the problem of using a list with for_each, it only turns it into an error.

for_each only works with sets and maps/objects. You need to turn your list into a set using toset() function.

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.

Was this page helpful?
0 / 5 - 0 ratings