0
0
Terraformcloud~30 mins

Variable types (string, number, bool, list, map) in Terraform - Mini Project: Build & Apply

Choose your learning style9 modes available
Terraform Variable Types Basics
📖 Scenario: You are setting up a simple Terraform configuration to manage cloud resources. You need to define variables of different types to customize your infrastructure setup.
🎯 Goal: Create a Terraform variables file that defines variables of types string, number, bool, list, and map with exact values. This will help you understand how to declare and use different variable types in Terraform.
📋 What You'll Learn
Define a string variable named region with value us-west-2
Define a number variable named instance_count with value 3
Define a bool variable named enable_monitoring with value true
Define a list variable named availability_zones with values ["us-west-2a", "us-west-2b"]
Define a map variable named tags with keys Environment and Owner and values Dev and Alice
💡 Why This Matters
🌍 Real World
Terraform variables let you customize infrastructure deployments without changing code. This is common in real cloud projects.
💼 Career
Understanding Terraform variable types is essential for cloud engineers and DevOps professionals managing infrastructure as code.
Progress0 / 4 steps
1
Create string and number variables
Create a Terraform variables file and define a string variable called region with the value "us-west-2" and a number variable called instance_count with the value 3.
Terraform
Hint

Use variable "name" { type = TYPE default = VALUE } syntax for each variable.

2
Add a boolean variable
Add a boolean variable called enable_monitoring with the value true to the existing Terraform variables file.
Terraform
Hint

Boolean variables use type = bool and default values are true or false.

3
Add a list variable
Add a list variable called availability_zones with the values ["us-west-2a", "us-west-2b"] to the Terraform variables file.
Terraform
Hint

List variables use type = list(string) and default is a list of strings.

4
Add a map variable
Add a map variable called tags with keys Environment and Owner and values Dev and Alice to the Terraform variables file.
Terraform
Hint

Map variables use type = map(string) and default is a map with key-value pairs.