Terraform Pre-Commit & Linting Toolchain Prompt
Stand up a layered Terraform quality gate — fmt, validate, tflint, tfsec/checkov, terraform-docs, and trivy — wired through pre-commit so the same checks run on laptops and in CI without bikeshedding.
- Target user
- Platform engineers standardizing Terraform repo hygiene
- Difficulty
- Beginner
- Tools
- Claude, ChatGPT
The prompt
You are a platform engineer who has rolled out Terraform pre-commit toolchains that teams actually keep enabled instead of `--no-verify`-ing past. I will provide: - My repo layout (mono vs many root modules, shared modules) - Current checks (probably just `terraform fmt`) - CI platform and how strict I can be - Team size and tolerance for friction Your job: 1. **Layer the checks** by speed and value: fast/local-only (`terraform fmt`, `terraform validate`), static lint (`tflint` with provider plugins + ruleset), security scan (`tfsec` or `checkov` or `trivy config`), docs (`terraform-docs` to keep READMEs in sync), and secret scan (`gitleaks`). Explain what each catches that the others don't, and where they overlap (so I don't run three scanners). 2. **The pre-commit config** — give a working `.pre-commit-config.yaml` using `antonbabenko/pre-commit-terraform`, pinned to a tag, with the hooks ordered fmt → validate → tflint → docs → security. Explain `args` for each (e.g. tflint init, terraform-docs output file). 3. **Same checks in CI** — run `pre-commit run --all-files` in CI so the gate is identical locally and remotely; no "passes on my machine." Show how to cache plugin downloads. 4. **Adoption strategy** — start with warn-only on existing violations, baseline the legacy findings, and ratchet to blocking for new code. This is the difference between a toolchain that sticks and one that gets disabled. 5. **Noise control** — how to suppress a finding correctly (inline ignore with a justification comment) vs globally, and how to review suppressions. Output as: (a) the pinned `.pre-commit-config.yaml`, (b) a starter `.tflint.hcl`, (c) the CI job, (d) the warn-then-block rollout plan, (e) the rule for justifying suppressions. Bias toward: fast feedback on the laptop, identical enforcement in CI, and a low enough friction floor that nobody bypasses it.