Terraform Infrastructure as Code Overview¶
Terraform is an infrastructure as code tool used to define and manage cloud and platform resources with declarative configuration files.
What Terraform Is Good For¶
- Creating cloud infrastructure
- Managing repeatable environments
- Tracking changes before applying them
- Keeping infrastructure definitions in version control
Core Terraform Concepts¶
- Provider: Plugin that connects Terraform to a platform such as AWS, Azure, or GCP
- Resource: Infrastructure object Terraform manages
- State: Record of what Terraform created and currently tracks
- Plan: Preview of proposed changes
- Apply: Step that creates or updates resources
Simple Example¶
How Terraform Works¶
- Initialize the working directory with
terraform init. - Review the execution plan with
terraform plan. - Apply changes with
terraform apply. - Store and protect state carefully.
How Terraform Talks to Cloud Providers¶
Terraform uses provider plugins, and those providers call the platform APIs on your behalf.
Examples:
hashicorp/awsfor AWShashicorp/azurermfor Azurehashicorp/googlefor GCP
Example provider block:
Typical Workflow¶
AWS CLI Setup¶
Terraform often works alongside the AWS CLI, especially during setup and testing.
Install on macOS:
Install on Windows:
Configure credentials:
Test access:
LocalStack for Safe Local Practice¶
LocalStack lets you test Terraform and AWS-style workflows locally without using a real AWS account.
Why Use It¶
- Avoid cloud cost during practice
- Test quickly in a local environment
- Learn Terraform flow more safely
Install LocalStack¶
Start It¶
Runs on http://localhost:4566.
Dashboard Example¶
These screenshots show the LocalStack interface during a local Terraform practice setup.

Quick Test¶
Docker Compose Example¶
version: "3.8"
services:
localstack:
image: localstack/localstack
ports:
- "4566:4566"
environment:
- SERVICES=s3,ec2,lambda
- DEBUG=1
volumes:
- "./localstack:/var/lib/localstack"
Start it with:
Terraform with LocalStack¶
Example project structure:
Example provider:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
required_version = ">= 1.5.0"
}
provider "aws" {
region = "us-east-1"
access_key = "test"
secret_key = "test"
s3_force_path_style = true
skip_credentials_validation = true
skip_metadata_api_check = true
}
Practical Advice¶
- Do not hardcode real credentials in configuration files
- Use remote state for team environments
- Review
planoutput before every apply - Separate learning labs from production workspaces
Next Steps¶
- Review Terraform interview questions
- Pair Terraform with Ansible when you need both provisioning and configuration