0
0
Terraformcloud~30 mins

Numeric functions (min, max, ceil) in Terraform - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Numeric Functions in Terraform
📖 Scenario: You are setting up a Terraform configuration to manage cloud resources. You need to use numeric functions to control resource counts and sizes based on given values.
🎯 Goal: Build a Terraform configuration that uses min, max, and ceil functions to calculate resource parameters.
📋 What You'll Learn
Create a variable with a list of numbers
Create a variable with a decimal number
Use min and max functions on the list
Use ceil function on the decimal number
💡 Why This Matters
🌍 Real World
Cloud engineers often need to calculate resource sizes or counts dynamically based on input values. Numeric functions like min, max, and ceil help automate these decisions.
💼 Career
Understanding Terraform numeric functions is essential for writing flexible infrastructure code that adapts to different environments and requirements.
Progress0 / 4 steps
1
Create a variable called numbers with the list [3, 7, 2, 9, 5]
Create a Terraform variable named numbers and assign it the list [3, 7, 2, 9, 5].
Terraform
Need a hint?

Use variable "numbers" { default = [...] } syntax to define the list.

2
Create a variable called decimal_value with the value 4.3
Create a Terraform variable named decimal_value and assign it the decimal number 4.3.
Terraform
Need a hint?

Use variable "decimal_value" { default = 4.3 } syntax to define the decimal number.

3
Create locals min_number and max_number using min and max functions on var.numbers
Create a locals block with two variables: min_number set to the minimum value of var.numbers using the min function, and max_number set to the maximum value of var.numbers using the max function.
Terraform
Need a hint?

Use min(var.numbers) and max(var.numbers) inside locals.

4
Add a local ceil_value using the ceil function on var.decimal_value
In the existing locals block, add a variable called ceil_value that uses the ceil function on var.decimal_value.
Terraform
Need a hint?

Add ceil_value = ceil(var.decimal_value) inside locals.