You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
but that is awkward and hard to read. It becomes even more so if there are multiple levels of possibly null objects that need to be traversed, especially since && isn't short circuiting.
Another option is to use try:
something= try(var.test.field1, "default")
the problem with this is that if I misspell something in var.test.field1, it will silently use the default instead of giving me an error.
Thanks for this feature request! If you are viewing this issue and would like to indicate your interest, please use the 👍 reaction on the issue description to upvote this issue. We also welcome additional use case descriptions. Thanks again!
Terraform Version
Use Cases
Suppose I have an optional variable like:
and then somewhere else I need to use use the value of
var.test.field
, but use a default value ofvar.test
is null.I would like to be able to do something like:
Attempted Solutions
I can of course do something like:
but that is awkward and hard to read. It becomes even more so if there are multiple levels of possibly null objects that need to be traversed, especially since
&&
isn't short circuiting.Another option is to use try:
the problem with this is that if I misspell something in
var.test.field1
, it will silently use the default instead of giving me an error.Proposal
Add a .? operator similar to javascript's optional chaining feature.
Or maybe add a function like
lookup
, except use the default value if the first argument is null.Or have a variant of
try
that will still fail for any other error than trying to look up a field on a null value.References
No response
The text was updated successfully, but these errors were encountered: