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

terraform 0.12 panics when calling distinct with empty list #21403

Closed
alex-goncharov opened this issue May 23, 2019 · 4 comments
Closed

terraform 0.12 panics when calling distinct with empty list #21403

alex-goncharov opened this issue May 23, 2019 · 4 comments
Assignees
Milestone

Comments

@alex-goncharov
Copy link

Terraform Version

$ terraform -v
Terraform v0.12.0

Terraform Configuration Files

locals {
  d = distinct([])
}

Debug Output

https://gist.github.com/alex-goncharov/d51af9a2b88a089cb32154abb031081a

Crash Output

https://gist.github.com/alex-goncharov/66f756fc609371862200e69a97b5f6f2

Expected Behavior

distinct returned empty list

Actual Behavior

terraform panics

Steps to Reproduce

create file with about hcl
terraform init && terraform plan

Additional Context

References

@apparentlymart
Copy link
Contributor

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:

return cty.ListVal(list), nil

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.

@antonbabenko
Copy link
Contributor

As a workaround to this issue I write it like this - compact(distinct(concat(var.maybe_empty, [""])))

https://github.com/terraform-aws-modules/terraform-aws-security-group/blob/687465a8f04af85fae13fd10d8982b12590debb7/modules/http-80/main.tf#L15

@apparentlymart apparentlymart self-assigned this May 31, 2019
@apparentlymart
Copy link
Contributor

This should be fixed by #21538.

@ghost
Copy link

ghost commented Jul 25, 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 Jul 25, 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