Function min()
📝 Description
The min function takes one or more numbers and returns the lowest (smallest) value from the set.
Tip: Just like with
max(), if you have a list of numbers, you must use the expansion symbol (...) to pass it into the function.
💻 Syntax
💡 Examples
1. Basic Usage:
2. Working with a List (Expansion):
3. Setting a Hard Limit (Real-world scenario):
Ensure that the number of requested nodes never exceeds your cloud quota (e.g., 10 nodes):
variable "user_requested_nodes" { default = 15 }
locals {
max_quota = 10
actual_nodes = min(var.user_requested_nodes, local.max_quota)
# Result: 10 (it picks the lower value to prevent exceeding the quota)
}
⚠️ Comparison: min() vs max()
| Input | min() (Lowest) | max() (Highest) |
|---|---|---|
5, 15, 25 |
5 | 25 |
-10, -20, 0 |
-20 | 0 |
0.5, 0.1, 0.9 |
0.1 | 0.9 |
🔗 Related Functions
-
[[max]] — The opposite: returns the largest value.
-
[[floor]] — Round down to the nearest integer.