.iac files, close to the resources they affect. ubx supports the null coalescing operator ??, if/else expressions that return a value, if without an else (returning null when false), and nested if/else chains for multi-branch logic. All of these are Resolved<T> — they evaluate at compile time from inputs and locals, producing plain values that get inlined into the generated code.
What you’ll learn
- The
??null coalescing operator — use an override if set, otherwise a default if/elseexpressions that return a value based on a conditionifwithout an else — evaluates to null when the condition is false- Nested
if/elsefor multi-branch logic (ubx does not supportelse if)
Why this matters
All conditional expressions in ubx are
Resolved<T> — they evaluate at compile time from inputs and locals. This means the generated Pulumi code contains plain values, not runtime conditionals. The environment logic lives in your .iac source, not scattered across separate stack files or wrapper scripts.The source code
How it works
Expressions are evaluated in the IR pass
During AST → IRProgram, all conditional expressions are evaluated against the resolved input values. The result is a plain
IRValue — a string, number, or bool. No conditional logic appears in the generated code.?? short-circuits on null
input.override_class ?? "db.t3.micro" evaluates the left side first. If the value is non-null, it’s used. If it’s null (the default), the right side is used. This is the cleanest pattern for optional overrides.if/else returns a value
Unlike many languages where
if is a statement, ubx’s if/else is an expression — it always produces a value. Both branches must return the same type. The result is inlined directly into the attribute that uses it.What ubx generates
Common mistakes
Run it
What you learned
?? returns the left side if non-null, otherwise the right side — clean pattern for optional overridesif/else is an expression in ubx — it returns a value and can be used anywhere a value is expectedif without else returns null when the condition is falseMulti-branch logic uses nested
if/else, not else ifNext steps
for_each over a list
Create multiple resources from a list
Language reference: conditionals
Full conditional expression syntax
Full runnable example: github.com/ubiquex/ubx-examples/05-conditional-expressions

