Terraform
This cheat sheet covers practical Terraform usage for managing infrastructure as code.
Getting Started
2 topics
Install Terraform
Steps to install Terraform on your system.
# On macOS
brew install terraform
# On Ubuntu
sudo apt-get update && sudo apt-get install -y terraformEnsure your PATH includes Terraform binaries.
Verify installation using `terraform --version`.
Initialize a Terraform Project
How to set up a new Terraform project.
# Create a directory for your project
mkdir my-terraform-project
cd my-terraform-project
# Initialize Terraform
terraform initRun `terraform init` whenever you add new providers.
Keep your project organized with a `main.tf` file.
Basic Configuration
2 topics
Define a Provider
Specify the cloud provider for Terraform to use.
provider "aws" {
region = "us-east-1"
}Always specify the region to avoid unexpected behavior.
Use environment variables for sensitive data like credentials.
Create a Resource
Define a resource to provision infrastructure.
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
}Use descriptive names for resources.
Check the AWS AMI IDs for your region.
State Management
2 topics
Understand Terraform State
Learn how Terraform tracks infrastructure state.
# Terraform state is stored in a file called 'terraform.tfstate'
# Example content:
{
"version": 4,
"resources": [
{
"type": "aws_instance",
"name": "example",
"instances": [
{
"attributes": {
"id": "i-0abcd1234efgh5678"
}
}
]
}
]
}Never manually edit the state file.
Use remote state for collaboration.
Remote State Configuration
Set up remote state storage for collaboration.
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "state/terraform.tfstate"
region = "us-east-1"
}
}Use versioning on your S3 bucket for state backups.
Secure your state file with encryption.
Variables and Outputs
2 topics
Define Variables
Use variables to make configurations reusable.
variable "instance_type" {
default = "t2.micro"
}
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = var.instance_type
}Use `default` for optional variables.
Group variables in a `variables.tf` file.
Define Outputs
Expose useful information after applying Terraform.
output "instance_id" {
value = aws_instance.example.id
}Use outputs for debugging and integration.
Group outputs in an `outputs.tf` file.
Advanced Topics
2 topics
Modules
Organize Terraform configurations using modules.
module "ec2_instance" {
source = "./modules/ec2"
instance_type = "t2.micro"
ami = "ami-0c55b159cbfafe1f0"
}Use modules for reusable configurations.
Store modules in a `modules` directory.
Terraform Workspaces
Manage multiple environments using workspaces.
# Create a new workspace
terraform workspace new dev
# Switch to an existing workspace
terraform workspace select devUse workspaces for staging and production environments.
Workspace names should be descriptive.
Related Cheat Sheets
More hands-on references connected to this topic.
Google Cloud Platform essentials: Compute Engine, GKE, Cloud Run, Cloud Storage, IAM, and core CLI commands.
shared topics, same difficulty
Runtime commands, package management, bundling, testing, and performance optimization.
same difficulty, keyword overlap
FastAPI routes, request models, dependency injection, authentication, and async patterns.
same difficulty, keyword overlap
React hooks, component patterns, state management, performance optimisation, and best practices.
same difficulty, keyword overlap
Related Articles
Background reading and deeper explanations for this sheet.
How to Create an Agent Using LangGraph: A Practical Developer Cheat Sheet
Want to build reliable AI agents instead of brittle prompt chains? This practical guide shows you how to create an agent using LangGraph step by step, from architecture and state design to tools, memory, and production hardening. You’ll get beginner-friendly explanations, real-world examples, and runnable code patterns you can adapt immediately.
keyword overlap
System Design Cheat Sheet: Practical Guide for Scalable Architecture
This system design cheat sheet gives you a practical, beginner-friendly framework to design scalable, reliable applications without getting lost in theory. You’ll learn what to evaluate, why each component matters, and how to make trade-offs with real-world examples you can use in interviews and production.
keyword overlap
FastAPI Interview Questions: Practical Cheat Sheet for Developers
Preparing for FastAPI interviews can feel overwhelming if you only memorize definitions. This practical cheat sheet helps you answer common FastAPI interview questions with confidence using real-world examples, production-ready patterns, and beginner-friendly explanations with depth.
keyword overlap
Generative AI Roadmap: A Practical, Beginner-Friendly Guide to Learning and Building Real Projects
Generative AI can feel overwhelming, but you don’t need a PhD to get started and create useful applications. This roadmap breaks down what to learn, when to learn it, and how to apply each skill in real-world projects—from prompt engineering and APIs to RAG, evaluation, and production deployment.
keyword overlap