Terraform Testing Cheat Sheet

Validate, plan, and policy-as-code

Last Updated: November 21, 2025

Stages

Step Purpose
fmt Canonical formatting
validate Schema + dependency checks
plan Preview changes
policy check Sentinel/Opa

Commands

terraform fmt -recursive
Format
terraform validate
Validate modules
terraform plan -out plan.tfplan
Store plan
sentinel test
Enforce guardrails

Advice

Test modules in isolation, reuse fixtures, and automate policy runs.

💡 Pro Tip: Add `terraform fmt` + `validate` to CI and guard changes with policies.
← Back to DevOps & Cloud | Browse all categories | View all cheat sheets