Terraform

Master Infrastructure as Code with HashiCorp Terraform. Learn to provision, manage, and version infrastructure across multiple cloud providers.

Intermediate 15+ Core Topics

Overview

Terraform is an open-source Infrastructure as Code tool that enables you to safely and predictably create, change, and improve infrastructure. This training covers HCL syntax, providers, state management, and production-ready patterns.

Core Concepts

  • HCL Syntax - HashiCorp Configuration Language basics
  • Providers - AWS, Azure, GCP, and 1000+ more
  • Resources - Declaring infrastructure components
  • Data Sources - Querying existing infrastructure
  • Variables & Outputs - Parameterization and values

State Management

  • Local State - Default state file management
  • Remote State - S3, Azure Blob, Terraform Cloud
  • State Locking - Prevent concurrent modifications
  • State Commands - import, mv, rm, pull, push

Sample AWS Configuration

# Configure the AWS Provider terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 5.0" } } backend "s3" { bucket = "my-terraform-state" key = "prod/terraform.tfstate" region = "us-east-1" encrypt = true dynamodb_table = "terraform-locks" } } provider "aws" { region = var.aws_region } # Create VPC resource "aws_vpc" "main" { cidr_block = var.vpc_cidr enable_dns_hostnames = true enable_dns_support = true tags = { Name = "${var.environment}-vpc" Environment = var.environment } } # Create EC2 Instance resource "aws_instance" "web" { count = var.instance_count ami = data.aws_ami.amazon_linux.id instance_type = var.instance_type subnet_id = aws_subnet.public[count.index].id tags = { Name = "${var.environment}-web-${count.index + 1}" } }

Modules

  • Module Structure - Organizing reusable components
  • Terraform Registry - Public module repository
  • Module Versioning - Semantic versioning
  • Module Composition - Nested modules

Workspaces & Environments

  • Workspaces - Multiple state environments
  • Environment Separation - Dev, staging, prod
  • .tfvars Files - Environment-specific variables

Terraform Workflow

# Initialize working directory terraform init # Validate configuration terraform validate # Format code terraform fmt -recursive # Plan changes terraform plan -out=tfplan # Apply changes terraform apply tfplan # Destroy infrastructure terraform destroy

Certification

  • HashiCorp Terraform Associate (003)