I was using the following pattern often in my code:
abc = something == null ? some_default : something
until I realised it can be more succinctly captured (especially when “something” is a more complex expression) as
abc = coalesce(something, some_default)
This is simple for anyone who knows
coalesce() BUT I find the intent is not as obvious as the more verbose version.
So I’m wondering if there is a yet better way. Eg the most obvious would have been
abc = ifnotnull(something, else_value)
defaults() function already available as experiment in HCL2 does not do the same:
defaults() requires that something be an input variable with a type, whereas sometimes
something is a local, and without an explicit type.
Is there a better way to communicate intent than using either the
if/then/else or the