How Terraform Works — Full Flow

Write Code (.tf files)
        |
        v
terraform init       <-- Downloads provider plugins, sets up backend
        |
        v
terraform validate   <-- Checks syntax errors
        |
        v
terraform plan       <-- Compares current state vs desired state, shows diff
        |
        v
terraform apply      <-- Applies the changes to real infrastructure
        |
        v
State File Updated   <-- terraform.tfstate updated with new real state
        |
        v
terraform destroy    <-- Destroys all managed resources (when needed)

Terraform Core Files

project/
├── main.tf           # Main resources
├── variables.tf      # Input variable declarations
├── outputs.tf        # Output value declarations
├── provider.tf       # Provider configuration
├── terraform.tfvars  # Actual variable values
├── backend.tf        # Remote state backend config
└── .terraform/       # Local plugins/cache (auto-generated by init)

Section 1 — Core Concepts (Must Know)

Q1. What is Terraform and why is it used?

Terraform is an open-source Infrastructure as Code (IaC) tool by HashiCorp. It lets you define cloud infrastructure (servers, databases, networks) in .tf files and manage them through code.

Why use Terraform:


Q2. What is Infrastructure as Code (IaC)?

IaC means managing and provisioning infrastructure through code/config files instead of manually clicking in a cloud console.

Benefits: