0
0
Terraformcloud~30 mins

Default values in Terraform - Mini Project: Build & Apply

Choose your learning style9 modes available
Terraform Default Values
📖 Scenario: You are setting up a simple Terraform configuration to create cloud resources. You want to use variables with default values so that the configuration works even if no values are provided by the user.
🎯 Goal: Build a Terraform configuration that defines a variable with a default value and uses it to create a resource with that default unless overridden.
📋 What You'll Learn
Define a Terraform variable with a default value
Use the variable in a resource configuration
Ensure the configuration is valid and deployable
💡 Why This Matters
🌍 Real World
Using default values in Terraform variables allows cloud infrastructure to be flexible and reusable without requiring users to always provide input.
💼 Career
Cloud engineers and DevOps professionals often use Terraform variables with defaults to create modular and easy-to-maintain infrastructure code.
Progress0 / 4 steps
1
Define a variable with a default value
Create a Terraform variable called instance_type with the default value t2.micro.
Terraform
Need a hint?

Use the variable block with default to set a default value.

2
Add a provider configuration
Add a Terraform provider block for AWS with the region set to us-east-1.
Terraform
Need a hint?

The provider block configures the cloud provider and region.

3
Create an EC2 instance resource using the variable
Create a resource block called aws_instance named example that uses the variable instance_type for its instance_type attribute and sets ami to ami-0c55b159cbfafe1f0.
Terraform
Need a hint?

Use var.instance_type to reference the variable inside the resource.

4
Add an output to show the instance type
Add an output block called instance_type_output that outputs the value of the variable instance_type.
Terraform
Need a hint?

Use an output block to display values after deployment.