Skip to main content

Terraform

Build, change, and version infrastructure safely and efficiently with HashiCorp Terraform.

Documentation

GuideDescription
Terraform FundamentalsHCL syntax, providers, resources, variables, state, data sources, exercises
Advanced TerraformModules, workspaces, remote state, Terragrunt, CI/CD, import, best practices
Command Cheat Sheet100+ CLI commands, HCL patterns, state operations, backend configuration
Exam PrepHashiCorp Terraform Associate (003) — domains, practice questions, study plan
Interview Questions40+ questions from beginner to advanced with detailed answers

Core Concepts

ConceptDescription
ProviderPlugin to interact with cloud APIs (AWS, Azure, GCP)
ResourceInfrastructure component to manage
StateTerraform's record of managed infrastructure
ModuleReusable, composable Terraform configuration
PlanPreview changes before applying
ApplyExecute planned changes

Learning Path

  1. Start with fundamentals — HCL syntax, providers, resources, variables, state
  2. Move to advanced patterns — modules, workspaces, remote backends, CI/CD
  3. Keep the cheat sheet handy — 100+ commands at your fingertips
  4. Prepare for certification — HashiCorp Associate exam domains and practice
  5. Practice interview questions — 40+ Q&A with detailed explanations

Quick Start

# main.tf — Example AWS EC2 instance
terraform {
required_providers {
aws = { source = "hashicorp/aws", version = "~> 5.0" }
}
}

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

resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t3.micro"
tags = { Name = "CloudCaptain-Web" }
}
terraform init      # Initialize working directory
terraform plan # Preview changes
terraform apply # Apply changes
terraform destroy # Destroy infrastructure
terraform fmt # Format configuration
terraform validate # Validate configuration

Best Practices

  • Use remote state (S3 + DynamoDB for AWS)
  • Lock state to prevent concurrent modifications
  • Use modules for reusable infrastructure
  • Implement workspaces for environment separation
  • Version pin providers and modules
  • Use terraform-docs for documentation
  • Scan with tfsec or checkov for security

External Resources

ResourceDescription
Terraform DocumentationOfficial HashiCorp docs
Terraform RegistryProviders, modules, and policies
How To Manage Secrets In TerraformProfessional secrets management
Reusable EC2 Instances Using ModulesTerraform modules best practices

Tools & Utilities

ToolDescription
terraformerGenerate tf/json files from existing infrastructure
terrascanDetect compliance and security violations in IaC
tfsecStatic analysis for Terraform security
checkovPolicy-as-code for cloud infrastructure
terraform-docsAuto-generate documentation from modules