-
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
Conditional expression does not always work in output variable #15165
Comments
Hi @jkehres! Sorry for the weird behavior here. I think what you're actually seeing here is the bug discussed in #9080: errors while evaluating outputs are not shown today, because we want to be able to try to evaluate outputs before all of their inputs are complete. This is also related to hashicorp/hil#50, which means that right now both "sides" of the conditional need to always be valid, even though only one is ever used. Were you to try the expression you have there in a resource attribute, I think you'd get an error saying that Here's a different way to write it that should work: value = "${element(compact(concat(list(var.topic_arn), aws_sns_topic.my_topic.*.arn)), 0)}" This should work because in both cases all of the variables can be resolved:
I totally understand that this convoluted expression creates maintenance headaches, so we're planning to address the limitations here and make this behave in a more intuitive way in future. Since we already have issues open covering the different aspects of this, I'm going to close it just to keep any further discussion in one place. Thanks for filing this issue! |
@apparentlymart I tried to adopt the idea of using "splat syntax" to workaround similar issue. but it does not work: original:
output test_list { workaround tried with splat syntax: value = ["${compact(concat(list(aws_instance.example1.id), aws_instance.example2.*.id))}"] both result in missing output of test_list. would you please suggest alternative to workaround this? I am using terraform v0.10.0 Thanks |
@RchenV did you find a workaround for this? I'm stuck here, too. |
@jnoxon I did find a workaround: value = ["${compact(concat(aws_instance.example1.*.id, aws_instance.example2.*.id))}"] does the trick. |
Sorry I didn't see these responses before... it's hard to keep track of discussions in closed issues. 😞 I'm glad to see you found a workaround in spite of my not seeing your question, @RchenV. For anyone else who finds this here: to work around the current issue that output errors are hidden, one approach is to evaluate the same expression in Note that |
@apparentlymart Thanks for the info on terraform console. I have not used it before. that is a great time-saving tool! |
I tried to boil down what I am doing to something very simple:
This works, but if I deploy it with use_random=true and then deploy again with use_random=false, I get no output from the second deploy. If I make no changes and deploy again, it works! |
@jnoxon that sounds like you've found a new bug, where perhaps the output isn't getting re-evaluated properly as the number of random id resources goes to zero. Would you mind opening a fresh issue for that? |
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. |
Terraform Version
0.9.7
Affected Resource(s)
Output variables
Terraform Configuration Files
Expected Behavior
When a non-empty value is given for the
topic_arn
input variable, the output variabletopic_arn
should be present.Actual Behavior
When a non-empty value is given for the
topic_arn
input variable, the output variabletopic_arn
is missing:However, when an empty (default) value is given for the
topic_arn
input variable, the output variabletopic_arn
is present:Steps to Reproduce
Run the following command with the HCL file shown above:
The text was updated successfully, but these errors were encountered: