Terraform Numeric Functions Cheatsheet

Terraform Numeric Functions Cheatsheet

This is a recap of Terraform numeric functions, to read the updated and complete documentation visit the hashicorp page.

min

min(set number) number

Given a set of numbers (or a compatible structure), this function returns the smallest one

>min(1,55,127,4,10)
1

>min([55,4,10]...)
4

max

max(set number) number

Given a set of numbers (or a compatible structure), this function returns the biggest one

>max(1,55,127,4,10)
127

>max([55,4,10]...)
55

parseint

parseint(string stringNumber, number base) number

Given a string representation of a number and its base, this function will return an integer.
The base must be between 2 and 62 inclusive.

>parseint("25", 10)
25

>parseint("1FF", 16)
511

>parseint("111", 2)
7

floor

floor(number num)

This function will return the closest whole number that is less or equal to the input number. The input number can be decimal.

>floor(11.9)
11

>floor(11)
11

floor(9.1)
9

ceil

ceil(number num)

This function will return the closest whole number that is greater or equal to the input number. The input number can be decimal.

>ceil(11.9)
12

>floor(11)
11

floor(9.1)
10

abs

abs(number num) number

Given an integer number, abs will return its absolute value. If the input number is negative, it will be multiplied by -1.

>abs(10)
10

>abs(-10)
10

>abs(0)
0

pow

pow(number num, number elevation)

This function will elevate the first argument num to the second argument elevation.

>pow(4,2)
16

>pow(3,1)
3

>pow(9,0)
1

signum

signum(number num)

This function returns a number representing the symbol of the input number.

>signum(-1)
-1

>signum(1)
1

>signum(9999)
1

>signum(0)
0