0
0
Terraformcloud~10 mins

Numeric functions (min, max, ceil) in Terraform - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Numeric functions (min, max, ceil)
Input Numbers
Apply min()
Apply max()
Apply ceil()
Output Results
The flow takes input numbers, applies min, max, and ceil functions step-by-step, then outputs the results.
Execution Sample
Terraform
variable "nums" {
  default = [1.2, 3.7, 2.5]
}
output "min_val" {
  value = min(var.nums...)
}
output "max_val" {
  value = max(var.nums...)
}
output "ceil_vals" {
  value = [for n in var.nums : ceil(n)]
}
This Terraform code finds the minimum, maximum, and ceiling values of a list of numbers.
Process Table
StepFunctionInputEvaluationResult
1min[1.2, 3.7, 2.5]Compare all numbers1.2
2max[1.2, 3.7, 2.5]Compare all numbers3.7
3ceil1.2Round up to nearest integer2
4ceil3.7Round up to nearest integer4
5ceil2.5Round up to nearest integer3
6Outputmin_valOutput min value1.2
7Outputmax_valOutput max value3.7
8Outputceil_valsOutput list of ceil values[2, 4, 3]
💡 All functions applied and outputs generated.
Status Tracker
VariableStartAfter Step 1After Step 2After Steps 3-5Final
var.nums[1.2, 3.7, 2.5][1.2, 3.7, 2.5][1.2, 3.7, 2.5][1.2, 3.7, 2.5][1.2, 3.7, 2.5]
min_valundefined1.21.21.21.2
max_valundefinedundefined3.73.73.7
ceil_valsundefinedundefinedundefined[2, 4, 3][2, 4, 3]
Key Moments - 3 Insights
Why does ceil(1.2) become 2 and not 1?
Ceil always rounds a number up to the nearest whole number, so 1.2 rounds up to 2 as shown in execution_table step 3.
Can min() and max() work on a list of numbers directly?
Yes, min() and max() compare all numbers in the list and return the smallest or largest value respectively, as seen in steps 1 and 2.
Why do we use a loop for ceil but not for min or max?
min() and max() take the whole list at once, but ceil() works on single numbers, so we apply it to each number individually, shown in steps 3-5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the result of max() at step 2?
A3.7
B1.2
C2.5
D4
💡 Hint
Check the 'Result' column in row with Step 2 for max function.
At which step does ceil(3.7) get evaluated?
AStep 3
BStep 4
CStep 5
DStep 2
💡 Hint
Look for the row where Function is 'ceil' and Input is 3.7.
If the input list changed to [2.1, 2.9], what would min_val be?
A3
B2.9
C2.1
D1.2
💡 Hint
min_val is the smallest number in the input list, see variable_tracker for min_val.
Concept Snapshot
Terraform numeric functions:
- min(list): returns smallest number
- max(list): returns largest number
- ceil(number): rounds number up
Use min/max on lists, ceil on each number
Outputs show results clearly
Full Transcript
This visual execution traces Terraform numeric functions min, max, and ceil. Starting with a list of numbers, min() finds the smallest value, max() finds the largest, and ceil() rounds each number up to the nearest integer. The execution table shows each step's input, evaluation, and result. Variables track how values change after each function. Key moments clarify why ceil rounds up and why min/max work on lists directly. The quiz tests understanding of function results and steps. This helps beginners see how these numeric functions behave in Terraform.