5 / 75 · 08 Infrastructure as Code Testing · Terraform Validation← prev⊞ allnext →☰ Read as one page
1.5The Complete Static Validation Pipeline
#!/bin/bash
# scripts/validate-terraform.sh
set -euo pipefail
echo "=== Stage 1: Format ==="
terraform fmt -check -recursive -diff
echo "=== Stage 2: Init + Validate ==="
terraform init -backend=false
terraform validate
echo "=== Stage 3: TFLint ==="
tflint --recursive
echo "=== Stage 4: Security Scan ==="
tfsec . --minimum-severity HIGH
echo "=== Stage 5: Compliance Scan ==="
checkov -d . --framework terraform --compact
echo "=== All static checks passed ==="
This script runs in under 30 seconds and catches the majority of issues before any cloud resources are involved.