Skip to content
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

0.12.6 Crashes when resource for_each given a list #22305

Closed
dpiddockcmp opened this issue Aug 2, 2019 · 4 comments
Closed

0.12.6 Crashes when resource for_each given a list #22305

dpiddockcmp opened this issue Aug 2, 2019 · 4 comments

Comments

@dpiddockcmp
Copy link

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

@ghost ghost added bug crash labels Aug 2, 2019
@kmoe
Copy link
Member

kmoe commented Aug 2, 2019

Thanks for the bug report. I'm pleased to say that this is fixed by #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.

@omeid
Copy link

omeid commented Aug 19, 2019

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.

@dpiddockcmp
Copy link
Author

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

@ghost
Copy link

ghost commented Sep 2, 2019

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.

@ghost ghost locked and limited conversation to collaborators Sep 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants