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
FAQ¶
What is Terraform used for?¶
Terraform is used to define and manage infrastructure with code. It is commonly used for cloud networks, compute, storage, IAM, Kubernetes platform dependencies, and repeatable environment setup.
What is the difference between Terraform and Ansible?¶
Terraform is strongest for provisioning infrastructure resources. Ansible is strongest for configuring systems and running operational tasks on existing hosts. Many teams use both together.
What is Terraform state?¶
Terraform state records what Terraform believes it manages. Treat state as important operational data, store team state remotely, and protect it from accidental edits or exposure.
How can I practice Terraform safely?¶
Use local labs such as LocalStack, isolated cloud sandboxes, small examples, and terraform plan reviews before applying changes.
Related Learning¶
- Terraform interview questions
- Ansible book series
- Multi-environment deployment design
- Backup and disaster recovery design
Next Steps¶
- Review Terraform interview questions
- Pair Terraform with Ansible when you need both provisioning and configuration