0
0
Terraformcloud~30 mins

Terraform file organization - Mini Project: Build & Apply

Choose your learning style9 modes available
Terraform File Organization
📖 Scenario: You are working on a cloud project where you need to organize your Terraform files properly. Good file organization helps you and your team understand and manage your infrastructure code easily.
🎯 Goal: Build a simple Terraform project with multiple files organized by purpose: one file for provider setup, one for variables, one for resources, and one for outputs.
📋 What You'll Learn
Create a provider.tf file with AWS provider configuration
Create a variables.tf file defining a variable for AWS region
Create a main.tf file with an AWS S3 bucket resource using the variable
Create an outputs.tf file that outputs the S3 bucket name
💡 Why This Matters
🌍 Real World
Organizing Terraform files is a common practice in real cloud projects to improve readability and collaboration.
💼 Career
Cloud engineers and DevOps professionals use Terraform file organization to manage infrastructure code efficiently in teams.
Progress0 / 4 steps
1
Create provider.tf with AWS provider
Create a file named provider.tf and write the AWS provider configuration with region set to us-east-1.
Terraform
Need a hint?

The AWS provider block starts with provider "aws" { and you set the region inside it.

2
Create variables.tf with AWS region variable
Create a file named variables.tf and define a variable called aws_region with default value us-east-1.
Terraform
Need a hint?

Use variable "aws_region" {} block and set default = "us-east-1".

3
Create main.tf with an S3 bucket resource
Create a file named main.tf and add an AWS S3 bucket resource named my_bucket. Use the variable aws_region for the bucket's region tag.
Terraform
Need a hint?

Use resource "aws_s3_bucket" "my_bucket" {} and set bucket and tags with Region = var.aws_region.

4
Create outputs.tf to output the bucket name
Create a file named outputs.tf and define an output called bucket_name that outputs the name of the S3 bucket resource my_bucket.
Terraform
Need a hint?

Use output "bucket_name" {} block and set value = aws_s3_bucket.my_bucket.bucket.