Jump to content

Welcome to CodeNameJessica

Welcome to CodeNameJessica!

💻 Where tech meets community.

Hello, Guest! 👋
You're just a few clicks away from joining an exclusive space for tech enthusiasts, problem-solvers, and lifelong learners like you.

🔐 Why Join?
By becoming a member of CodeNameJessica, you’ll get access to:
In-depth discussions on Linux, Security, Server Administration, Programming, and more
Exclusive resources, tools, and scripts for IT professionals
A supportive community of like-minded individuals to share ideas, solve problems, and learn together
Project showcases, guides, and tutorials from our members
Personalized profiles and direct messaging to collaborate with other techies

🌐 Sign Up Now and Unlock Full Access!
As a guest, you're seeing just a glimpse of what we offer. Don't miss out on the complete experience! Create a free account today and start exploring everything CodeNameJessica has to offer.

Chapter 2: Getting Started - Your First Steps

(0 reviews)
by: Akhilesh Mishra
Fri, 28 Nov 2025 15:34:33 +0530


Chapter 2: Getting Started - Your First Steps

Step 1: Install Terraform

For macOS users:

brew install terraform

For Windows users: Download from the official Terraform website and add it to your PATH.

For Linux users:

wget https://releases.hashicorp.com/terraform/1.12.0/terraform_1.12.0_linux_amd64.zip
unzip terraform_1.12.0_linux_amd64.zip
sudo mv terraform /usr/local/bin/

Step 2: Verify Installation

terraform version

You should see something like:

Terraform v1.12.0

Step 3: Create Your First Terraform File

Create a new directory for your first Terraform project:

mkdir my-first-terraform
cd my-first-terraform

Create a file called main.tf and add this simple configuration:

# This is a comment in Terraform
resource "local_file" "hello" {
content = "Hello, Terraform World!"
filename = "hello.txt"
}	

This simple example creates a text file on your local machine. Not very exciting, but it’s a great way to see Terraform in action without needing cloud credentials.

Step 4: The Magic Commands

Now comes the fun part! Run these commands in order:

Initialize Terraform:

terraform init
Terraform init command and its output
Terraform Init

This downloads the providers (plugins) needed for your configuration.

See what Terraform plans to do:

terraform plan
Terraform Plan
Terraform Plan

This shows you exactly what changes Terraform will make.

Apply the changes:

terraform apply
Terraform Apply Command and its Output
Terraform Apply

Type yes when prompted, and watch Terraform create your file!

Clean up:

terraform destroy
Terraform Destroy command and its output
Terraform Destroy

This removes everything Terraform created.

What Just Happened?

Congratulations! You just used Terraform to manage infrastructure (even if it was just a simple file). Here’s what each command did:

  • terraform init: Set up the working directory and downloaded necessary plugins
  • terraform plan: Showed you what changes would be made
  • terraform apply: Actually made the changes
  • terraform destroy: Cleaned everything up

This same pattern works whether you’re creating a simple file or managing thousands of cloud resources.

Essential Terraform Commands

Beyond the basic workflow, here are commands you’ll use daily:

terraform validate - Check if your configuration is syntactically valid:

terraform validate
Terraform validate command with success message.
Terraform Validate

Run this before plan. Catches typos and syntax errors instantly.
terraform fmt - Format your code to follow standard style:

terraform fmt
Format the Terraform files using the terraform fmt command. Before and after formating the code.
Terraform Format

Makes your code consistent and readable. Run it before committing.
terraform show - Inspect the current state:

terraform show
Terraform show command and its output
Terraform Show

Shows you what Terraform has created.
terraform output - Display output values:

terraform output
The terraform output command and its result.
Terraform Output

Useful for getting information like IP addresses or resource IDs.
terraform console - Interactive console for testing expressions:

terraform console

Test functions and interpolations before using them in code. Type exit to quit.
terraform refresh - Update state to match real infrastructure:

terraform refresh
📋
Deprecated in favor of terraform apply -refresh-only, but worth knowing.

Common Command Patterns

See plan without applying:

terraform plan -out=tfplan
See plan without applying in Terraform
See Plan

Apply saved plan:

terraform apply tfplan

Auto-approve (careful!):

terraform apply -auto-approve

Destroy specific resource:

terraform destroy -target=aws_instance.example

Format all files recursively:

terraform fmt -recursive

These commands form your daily Terraform workflow. You’ll use init, validate, fmt, plan, and apply constantly.

Terraform Daily Commands Cheat Sheet
Terraform Daily Commands

Now that you understand what Terraform is and how to use its basic commands, let’s dive deeper into the core concepts that make Terraform powerful. We’ll start with variables and locals—the building blocks that make your infrastructure code flexible and reusable.

I have also built Living DevOps platform as a real-world DevOps education platform.

I’ve spent years building, breaking, and fixing systems in production. Now I teach what I’ve learned in my free time.

You’ll find resources, roadmaps, blogs, and courses around real-world DevOps. No fluff. No theory-only content. Just practical stuff that actually works in production.

Living With DevOps

0 Comments

Recommended Comments

There are no comments to display.

Guest
Add a comment...

Important Information

Terms of Use Privacy Policy Guidelines We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.