How to use the Terraform Cheat Sheet
- 1. Search or browseType what you want to do, or pick one section of the Terraform cheat sheet.
- 2. CopyEvery entry has its own Copy button, so it goes straight into your editor or notes.
- 3. DownloadSave the whole Terraform cheat sheet as plain text or Markdown for offline revision.
What's in it
Examples use the AWS provider, but the language, CLI and state commands are the same for Azure, Google Cloud and others. Commands match Terraform 1.x; OpenTofu uses the same syntax with the tofu command. The 32 entries are organised into 7 sections: CLI workflow, Provider & backend, Resources, Variables & outputs, Data & modules, Expressions, State.
Example
Creating one IAM user per teammate? for_each = toset(["asha", "ravi"]) with name = each.key makes two users addressed as aws_iam_user.dev["asha"] and aws_iam_user.dev["ravi"]. Remove "ravi" later and only that user is destroyed. With count = 2 instead, removing the first item would shift indexes and recreate the other user, which is why for_each is usually safer for named things.
Tips for using it
- Run
terraform planand read it before every apply, especially lines marked with -/+ (replace). - Keep state in a remote backend with locking as soon as more than one person works on the code.
- Mark secrets as sensitive, but remember they still sit in the state file; protect the state bucket.
A quick look, one entry per section
- CLI workflow:
terraform init(download providers and set up the backend; run first in every new folder) - Provider & backend:
terraform {(pin the provider version and set the region (ap-south-1 is Mumbai)) - Resources:
resource "aws_s3_bucket" "site" {(a resource: type, local name, then arguments) - Variables & outputs:
variable "env" {(input variable with a validation rule) - Data & modules:
data "aws_ami" "ubuntu" {(data source: look up something that already exists (099720109477 is Canonical's account)) - Expressions:
instance_type = var.env == "prod" ? "t3.large" : "t3.micro"(conditional expression) - State:
terraform state list(everything in state)
Search the box above for the rest of the Terraform entries, or download the full sheet.
Frequently asked questions
Is use_lockfile available everywhere?
S3-native state locking with use_lockfile arrived in Terraform 1.10. On older versions, use a DynamoDB table for locking.
Does it help with the Terraform Associate exam?
Yes, it covers the CLI and language topics in the exam. Pair it with our Terraform Associate practice test.
Is the Terraform cheat sheet free?
Yes. You can search, read and copy every entry in the Terraform cheat sheet without signing up. The first time you download it, we ask once for your name and WhatsApp number; after that downloads and every other Uncodemy tool open straight away.