Test infrastructure code before deploying to production.
Testing approaches:
- Static analysis:
terraform validate,tflint,checkov - Plan review:
terraform planoutput in PR comments - Integration tests: Terratest (Go), kitchen-terraform
- Policy as code: OPA/Rego, Sentinel
Terratest example:
func TestVpc(t *testing.T) {
opts := &terraform.Options{TerraformDir: "../modules/vpc"}
defer terraform.Destroy(t, opts)
terraform.InitAndApply(t, opts)
}
Interview tip: Mention infrastructure testing when discussing IaC. It signals operational maturity.