-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Objects incorrectly cast to null when used in a conditional with null #21395
Comments
WorkaroundAt least for outputs, if you reference a resource object in an output and it is specified in the config but has has count=0, then it just comes back as an empty list rather than erroring out, so for this circumstance of "optional resources", doing a condition check isn't necessary. It will still error if you specify a resource that doesn't exist in the config. resource "local_file" "example" {
count = 0
filename = "mytestfile.txt"
content = "This is a test file"
}
#Returns empty list instead of erroring (which is nice)
output "test" {
value = local_file.example
}
|
I've also run into this problem in my configs. I have several object outputs that keep giving null in a true-false expression. output "autoscaling_group" {
description = "Auto scaling group for node instances."
value = var.create_nodes ? aws_autoscaling_group.this[0] : null
} In my case, I worked around it by coalesce the conditional resource with a list containing a null, and selecting the first element. output "autoscaling_group" {
description = "Auto scaling group for node instances."
value = coalescelist(aws_autoscaling_group.this, [null])[0]
} |
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. |
Congrats on 0.12 release
Terraform Version
Terraform Configuration Files
Debug Output
https://gist.github.com/JustinGrote/2c7b9fc4aec47e14ddae975d3065c4cc
Expected Behavior
Anywhere that a conditional with a null in it should have resulted in an output with that object
Actual Behavior
No output was shown. Assumption is that it cast to "null".
Steps to Reproduce
terraform init
terraform apply
terraform apply -var 'switch=false'
The text was updated successfully, but these errors were encountered: