Terraform Day 01: Getting Started with Infrastructure as Code

Abdul RaheemAbdul Raheem
3 min read

Intro:
Today I started my Terraform with AWS learning journey. Before diving into AWS, I wanted to get clear on the fundamentals — what Terraform actually is and how to set it up. After that, I moved straight into deploying my first Nginx server on AWS using Terraform.


🔹 What is Terraform?

Terraform is an open-source Infrastructure as Code (IaC) tool created by HashiCorp. It allows you to define your infrastructure (servers, networks, storage, etc.) in code and then automatically provision it.

  • Instead of manually creating resources in the AWS console, you write code.

  • This code is reusable, shareable, and version-controlled.

  • Terraform supports multiple cloud providers (AWS, Azure, GCP, etc.), making it cloud-agnostic.


🔹 Installing Terraform

Steps I followed to install Terraform on my machine:

  1. Download Terraform binary from terraform.io

  2. Add it to system PATH

  3. Verify installation with:

     terraform -version
    

🔹 First Hands-On: Deploying Nginx on AWS

After installation, I configured AWS credentials and created my first Terraform file (main.tf) to deploy an EC2 instance with Nginx installed.

Code snippet:

provider "aws" {
  region = "us-east-1"
}

resource "aws_instance" "nginx" {
  ami           = "ami-123456"  # Ubuntu AMI
  instance_type = "t2.micro"

  user_data = <<-EOF
              #!/bin/bash
              sudo apt update -y
              sudo apt install nginx -y
              EOF

  tags = {
    Name = "Terraform-Nginx"
  }
}

Commands used:

terraform init  
terraform plan  
terraform apply

🔹 Understanding Terraform Commands

When working with Terraform, you usually follow a workflow of Init → Plan → Apply. Here’s what each command does:


1️⃣ terraform init

  • This command initializes your working directory for Terraform.

  • It downloads the required provider plugins (like AWS, Azure, GCP) so Terraform can communicate with the chosen cloud.

  • It also sets up the .terraform folder in your project where dependencies are stored.

👉 Think of it as “setting up the environment before building anything.”
If you don’t run init, Terraform won’t know how to talk to AWS.


2️⃣ terraform plan

  • This command shows you what Terraform will do before making any actual changes.

  • It compares your code (.tf files) with the current infrastructure state.

  • The output will clearly list:

    • Resources to be created

    • Resources to be modified

    • Resources to be destroyed

👉 Think of it as a dry run or preview mode.
This is super useful in real-world projects because you want to double-check changes before applying them on production.


3️⃣ terraform apply

  • This command executes the plan and actually provisions (creates/updates/destroys) resources on AWS.

  • Terraform will first ask for confirmation:

      Do you want to perform these actions?
        Only 'yes' will be accepted to approve.
    
  • After typing yes, Terraform will call AWS APIs and provision the resources as described in your code.

👉 Think of it as the final step where your infrastructure comes alive.


Quick Summary in One Line:

  • init → Get ready

  • plan → Show me what will happen

  • apply → Make it happen 🚀


🔹 Reflection

Day 01 taught me two important things:

  • Terraform makes AWS provisioning much faster and repeatable

  • Even a simple Nginx server shows the power of IaC

👉 Full code available on my GitHub


0
Subscribe to my newsletter

Read articles from Abdul Raheem directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Abdul Raheem
Abdul Raheem

Cloud DevOps | AWS | Terraform | CI/CD | Obsessed with clean infrastructure. Cloud DevOps Engineer 🚀 | Automating Infrastructure & Securing Pipelines | Bridging Gaps Between Code and Cloud ☁️ I’m on a mission to master DevOps from the ground up—building scalable systems, automating workflows, and integrating security into every phase of the SDLC. Currently working with AWS, Terraform, Docker, CI/CD, and learning the art of cloud-native development.