$ terraform -v
Terraform v0.12.0
locals {
d = distinct([])
}
https://gist.github.com/alex-goncharov/d51af9a2b88a089cb32154abb031081a
https://gist.github.com/alex-goncharov/66f756fc609371862200e69a97b5f6f2
distinct returned empty list
terraform panics
create file with about hcl
terraform init && terraform plan
Sorry for this crash @alex-goncharov, and thanks for reporting it.
This seems to just be a missing case not handled in the function implementation, here:
cty.ListVal relies on getting a non-empty list in order to know what element type the resulting list will have, so it panics if given an empty list. This should be fixable then by adding an extra guard condition just before:
if len(list) == 0 {
return cty.ListValEmpty(retType.ElementType), nil
}
We'll get this fixed up! Thanks again for reporting it.
As a workaround to this issue I write it like this - compact(distinct(concat(var.maybe_empty, [""])))
This should be fixed by #21538.
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.
Most helpful comment
Sorry for this crash @alex-goncharov, and thanks for reporting it.
This seems to just be a missing case not handled in the function implementation, here:
https://github.com/hashicorp/terraform/blob/f68673fbe4ae7f97741a60979a56afbff6f3b53d/lang/funcs/collection.go#L366
cty.ListValrelies on getting a non-empty list in order to know what element type the resulting list will have, so it panics if given an empty list. This should be fixable then by adding an extra guard condition just before:We'll get this fixed up! Thanks again for reporting it.