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.
More on Testing and Policy as Code
What does the static-analysis layer catch?BeginnerWhat does tflint do, and how is it configured?BeginnerHow do Checkov and Trivy differ?IntermediateHow does `terraform test` work?BeginnerHow do mock providers work in `terraform test`?AdvancedWhen do you use Terratest instead of `terraform test`?Intermediate