Table of Contents
- Interactive Arithmetic in the Console
- Equality & Inequality Operators
- Comparison Operators
- Logical Operators & NOT
- Defining Variables and Testing Expressions
- Ternary (Conditional) Expressions in Configurations
- References
Interactive Arithmetic in the Console
You can quickly evaluate math expressions in the OpenTofu console:Equality & Inequality Operators
Equality and inequality comparisons return a Boolean. Use them to compare values of any type:The operators
== and != are type-sensitive. A number and a string holding the same digits are considered unequal.Comparison Operators
Numeric comparisons also yield Boolean results. Here’s a quick reference:| Operator | Description | Example |
|---|---|---|
> | Greater than | 5 > 4 → true |
>= | Greater than or equal to | 5 >= 5 → true |
< | Less than | 3 < 4 → true |
<= | Less than or equal to | 3 <= 3 → true |
Logical Operators & NOT
Combine Boolean expressions using AND (&&) and OR (||), and invert them with NOT (!):
Defining Variables and Testing Expressions
You can declare variables in HCL and reference them in the console:Ternary (Conditional) Expressions in Configurations
Use the ternary operator (condition ? true_val : false_val) to enforce defaults. For example, generate a random password whose length is at least 8 characters:
Always enforce a minimum length for generated passwords to maintain security standards.
length=5, OpenTofu generates an 8-character password. Passing a higher value (e.g., 12) yields a 12-character result.