Interview Prep/Terraform/Testing and Policy as Code

How do you test infrastructure code, and what does the testing pyramid look like?

BeginnerProductionTesting and Policy as Code
Answer

Bottom to top: static checks (fmt, validate, tflint), security and policy scans (Checkov, Trivy, OPA), plan-level tests (terraform test with command = plan, mock providers), then real integration tests that apply into a sandbox account (terraform test with apply, Terratest) and finally smoke checks after deploy. Many cheap tests, few expensive ones.

All Terraform questions Roadmap: Terraform in production

More on Testing and Policy as Code