Skip to content

Function ceil()

📝 Description

The ceil function (short for "ceiling") returns the closest whole number that is greater than or equal to the given value. It effectively "rounds up" to the nearest integer.

Use Case: Essential for capacity planning. If your calculation says you need 2.1 virtual machines, ceil will ensure you provision 3.


💻 Syntax

ceil(number)

💡 Examples

1. Basic Rounding Up:

# Result: 3
output "round_up" {
  value = ceil(2.1)
}

2. Negative Numbers (Be Careful!):

In the negative scale, the "greater" number is the one closer to zero.

# Result: -2
output "round_negative" {
  value = ceil(-2.9)
}

3. Capacity Calculation (Real-world scenario):

If you want to provision 1 CPU for every 4GB of RAM, and you have 10GB:

locals {
  ram_gb = 10
  cpu_cores = ceil(local.ram_gb / 4) # 10 / 4 = 2.5 -> Result: 3
}

⚠️ Comparison Table

Input ceil() (Up) floor() (Down)
1.1 2 1
1.9 2 1
2.0 2 2
-1.5 -1 -2