In the previous blog (Part 1), we learned what Terraform is and why it’s a game changer for Infrastructure as Code (IaC).
Now, let’s get our hands dirty and build your very first Terraform project.
This blog will walk you through:
- Setting up a Terraform project
- Creating your first infrastructure resource
- Understanding the Terraform workflow step-by-step
What We’re Building
We’ll create a simple AWS S3 bucket using Terraform. Why S3?
Because it’s:
- Free-tier friendly
- Simple to create
- Widely used for hosting files, backups, even static websites
By the end, you’ll have a working S3 bucket managed entirely through code.
Step 1: Project Setup
Create a folder for your project:
mkdir terraform-hello-world
cd terraform-hello-world
Inside this folder, we’ll have:
main.tf # Our Terraform configuration
Step 2: Write the Terraform Configuration
Open main.tf
and add:
# Define AWS provider and region
provider "aws" {
region = "us-east-1"
}
# Create an S3 bucket
resource "aws_s3_bucket" "my_bucket" {
bucket = "my-first-terraform-bucket-1234"
acl = "private"
}
Here’s what’s happening:
- provider "aws" → Tells Terraform we’re using AWS.
- resource "aws_s3_bucket" → Creates an S3 bucket with the given name.
Step 3: Initialize Terraform
In your terminal, run:
terraform init
This:
- Downloads the AWS provider plugin
- Prepares your project for use
Step 4: See What Terraform Will Do
Run:
terraform plan
You’ll see output like:
Plan: 1 to add, 0 to change, 0 to destroy.
It’s like a dry run before making changes.
Step 5: Create the S3 Bucket
Now apply the changes:
terraform apply
Terraform will ask:
Do you want to perform these actions?
Type yes
, and in seconds, your bucket is live on AWS.
Step 6: Verify in AWS Console
Log in to your AWS Console → S3.
You’ll see my-first-terraform-bucket-1234
created automatically.
Step 7: Clean Up (Optional)
Want to delete the bucket? Run:
terraform destroy
Type yes
, and Terraform removes it safely.
Case Study: Speeding Up Dev Environments
A small dev team used to manually create test environments on AWS.
With Terraform:
-
They wrote one
main.tf
file
- Now spin up identical test environments in 5 minutes instead of 2 hours
- Delete everything in one command when done
Result: Saved time, fewer manual errors, and consistent setups.
Understanding Terraform Workflow
Terraform always follows this cycle:
Init → Plan → Apply → Destroy
Step | Command | Purpose |
---|---|---|
Initialize | terraform init |
Sets up project & downloads providers |
Plan | terraform plan |
Shows what changes will happen |
Apply | terraform apply |
Creates or updates resources |
Destroy | terraform destroy |
Deletes resources created by Terraform |
What’s Next?
This was a single resource. But real-world projects have:
- Multiple resources
- Variables for flexibility
- Outputs for sharing information