Function abs()
📝 Description
The abs function returns the absolute value of a given number. In simpler terms, it removes the minus sign if the number is negative and leaves it as is if it's positive.
Note: The input must be a number (integer or float). If you pass a string that looks like a number, Terraform will try to convert it automatically.
💻 Syntax
💡 Examples
1. Basic Usage (Negative to Positive):
2. Positive remains Positive:
3. Using with Variables (Real-world scenario):
Imagine you are calculating a budget offset and want to ensure the result is always a positive "distance" from zero:
⚠️ Common Errors
| Input | Result | Why? |
|---|---|---|
abs("hello") |
Error | Input must be a number, not a string. |
abs(null) |
Error | Cannot calculate absolute value of a null object. |
🔗 Related Functions
-
[[ceil]] — Round up to the nearest integer.
-
[[floor]] — Round down to the nearest integer.