0
0
Terraformcloud~15 mins

Terraform fmt for formatting - Mini Project: Build & Apply

Choose your learning style9 modes available
Terraform fmt for formatting
📖 Scenario: You are working on a Terraform project to manage cloud infrastructure. Your Terraform files need to be clean and easy to read for your team.
🎯 Goal: Learn how to use terraform fmt to automatically format Terraform configuration files for better readability and consistency.
📋 What You'll Learn
Create a Terraform configuration file with unformatted code
Add a variable block with a default value
Write a resource block with minimal formatting
Apply terraform fmt to format the code properly
💡 Why This Matters
🌍 Real World
Terraform fmt is used by cloud engineers to keep infrastructure code clean and consistent, making collaboration easier.
💼 Career
Knowing terraform fmt is essential for cloud infrastructure roles to maintain readable and standardized Terraform code.
Progress0 / 4 steps
1
Create an unformatted Terraform configuration file
Create a file named main.tf with this exact unformatted content: variable "region"{default="us-west-2"}resource "aws_s3_bucket" "bucket"{bucket="mybucket"}
Terraform
Need a hint?

Write the variable and resource blocks without spaces or new lines as shown.

2
Add a variable block with default value
Add a variable block named environment with a default value of dev to the existing main.tf file.
Terraform
Need a hint?

Write the variable block exactly as variable "environment" {default = "dev"}.

3
Add a minimally formatted resource block
Add a resource block named aws_instance with the name web and an attribute ami set to ami-123456 in main.tf. Write it without extra spaces or new lines.
Terraform
Need a hint?

Write the resource block exactly as resource "aws_instance" "web"{ami="ami-123456"}.

4
Format the Terraform configuration using terraform fmt
Run the command terraform fmt in the directory containing main.tf to format the Terraform configuration file properly.
Terraform
Need a hint?

Use the terraform fmt command in your terminal to format the file.