Terraform | Sheetly Cheat Sheet

Last Updated: November 21, 2025

Terraform

Infrastructure as Code tool

Core Concepts

Item Description
Provider Plugin for cloud/service API
Resource Infrastructure component
Module Reusable configuration
State Current infrastructure mapping
Variable Input parameter
Output Exported value
Data Source Read-only external data

Common Commands

terraform init
Initialize working directory
terraform plan
Preview changes
terraform apply
Create/update infrastructure
terraform destroy
Remove all resources
terraform fmt
Format configuration files
terraform validate
Check configuration syntax

Configuration Example

# Provider configuration
provider "aws" {
  region = "us-east-1"
}

# VPC resource
resource "aws_vpc" "main" {
  cidr_block = "10.0.0.0/16"

  tags = {
    Name = "main-vpc"
  }
}

# EC2 instance
resource "aws_instance" "web" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"

  tags = {
    Name = "web-server"
  }
}

# Output values
output "instance_ip" {
  value = aws_instance.web.public_ip
}

Best Practices

  • Use remote state with locking
  • Organize code with modules
  • Use workspaces for multiple environments
  • Always run terraform plan before apply

💡 Pro Tips

Quick Reference

Use terraform workspaces to manage multiple environments

← Back to DevOps & Cloud | Browse all categories | View all cheat sheets