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 destroy fails due to empty coalesce in output #51

Closed
schollii opened this issue Jun 25, 2020 · 2 comments
Closed

terraform destroy fails due to empty coalesce in output #51

schollii opened this issue Jun 25, 2020 · 2 comments
Labels
bug 🐛 An issue with the system

Comments

@schollii
Copy link
Contributor

Describe the Bug

Using terraform 0.12:

  1. create a main.tf that uses this module
  2. terraform init and apply
  3. terraform destroy

eventually the following happens:

$ terraform destroy
...
Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes


Error: Error in function call

  on .terraform/modules/terraform_state_backend/output.tf line 30, in output "dynamodb_table_id":
  30:     coalescelist(
  31: 
  32: 
  33: 
    |----------------
    | aws_dynamodb_table.with_server_side_encryption is empty tuple
    | aws_dynamodb_table.without_server_side_encryption is empty tuple

Call to function "coalescelist" failed: no non-null arguments.

Expected Behavior

It should have finished properly. Looks like the coalesce is incorrect.

Fix

This is likely due to the new behavior of coalescelist() in terraform 0.12.

Add [""] to the coalesclist() call. I will try to submit a PR.

@schollii
Copy link
Contributor Author

schollii commented Jun 25, 2020

So upon further thought, adding the empty string list is a hack for backwards compat with terraform 0.11, because the 0.12 coalescelist behavior is correct: the function returns the first non-empty list so if they are all empty, it does not make sense to return anything and it should raise an exception.

The deeper issues are:

  1. that terraform tries to render outputs as part of a destroy, which doesn't make sense in general and is likely to have other similar issues with undefined objects. See my comment Coalescelist broken in 0.12 hashicorp/terraform#25390 (comment).
  2. that coalescelist() is defined that way; probably the function should be "returns the first non-empty list, or an list list if they are all empty". Problem there is this will cause outer code to break (eg the element(coalesced-list, 0) to break in 0.12, so it doesnt' really solve the problem.

@nitrocode
Copy link
Member

This issue seems resolved @schollii . If not, please comment the ticket again.

Thanks again for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue with the system
Projects
None yet
Development

No branches or pull requests

2 participants