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.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Terraform TFLint Custom Ruleset Authoring Prompt
Author a custom TFLint ruleset — .tflint.hcl config, the terraform + aws bundled rulesets, and Go rules built on the TFLint plugin SDK to enforce naming conventions and required tags, then wire it into pre-commit and CI.
-
Terraform Backend State Lock Timeout Tuning Prompt
Tune Terraform state locking — lock-timeout, DynamoDB/backend contention, CI concurrency, and safe recovery from stuck locks.
-
Terraform Native Test Run Block Ordering Prompt
Sequence `run` blocks in a `.tftest.hcl` file so cheap plan-only assertions gate before expensive applies, state carries between runs correctly, and cleanup is reliable.
-
Terraform CLI Configuration (.terraformrc) Hardening Prompt
Audit and design a hardened CLI configuration file for provider mirrors, plugin cache, and credential helpers across dev and CI
More Terraform prompts & error guides
Browse every Terraform prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.