FormingSkillclaude-codepublished fresh until

How do I catch insecure Terraform while my agent is writing it?

Summary When checking agent-written Terraform for insecure settings, add deterministic Checkov, Trivy, or OPA checks in hooks, pre-commit, or CI; instructions in CLAUDE.md are not a guardrail.

Not for plan-level policy gates on Terraform; see gate-agent-terraform-with-opa-policies

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

The option

Option
ASkill · v1.0.0terraform-style-guide skill (HashiCorp)
How you use itYou ask for it
What it can dowrites files
What's inside
ASkill · v1.0.0terraform-style-guide skill (HashiCorp)
How you use it
You ask for it
What it can do
writes files
What's inside

What this thread does

The problem

You ask an agent for "an RDS instance for my orders service" and get Terraform that validates and plans fine but has no encryption, no deletion protection or an open security group. You would like that caught before a PR, not after.

What the source says

An r/Terraform thread (5 September 2026, by u/Ano--05007, the author of a Checkov-based MCP server) announced a tool that scans Terraform while the agent writes it. The replies are more useful than the tool:

  • Steering is not a guardrail. A commenter says prompts and instruction files are suggestions: what you trust the model to follow cannot also be the thing that verifies it; build the flow so the model cannot skip the controls.
  • Existing deterministic checks already work. Another commenter says their process barely changed after adopting Claude Code: same Git hooks locally and same CI, because the checks humans need also work for agents. Another asks why spend model tokens when Trivy, Checkov, tfsec or OPA exist, and suggests pre-commit or an agent hook. A third prefers pre-commit with OPA policies that encode their own standards.
  • The tool itself. The maker confirmed it wraps Checkov and adds compact findings, remediation snippets and templates; he also conceded that a hook gives the same scan-after-write behaviour.

A hook-based version

This is my sketch of the pattern the commenters describe; I have not run it. In Claude Code, a PostToolUse hook on Edit|Write receives the tool input as JSON on stdin; exiting with code 2 feeds stderr back to the agent. The hook script could be:

#!/bin/sh
f=$(jq -r '.tool_input.file_path // empty')
case "$f" in
  *.tf) checkov -f "$f" --compact --quiet >&2 || exit 2 ;;
esac

Register it under hooks.PostToolUse with matcher Edit|Write in .claude/settings.json (check the current hooks docs for the exact shape), keep the same Checkov or Trivy run in pre-commit and CI so the check also fires when the agent is not involved, and store the script and config where the agent cannot edit them.

How to describe it to your agent

A hook runs Checkov after each .tf edit made through Edit or Write. If it reports findings, fix them in the Terraform; do not add skip comments or edit the hook or its config. If a finding is a deliberate exception, list it for me instead.

Mistakes to check

  • Letting the agent add #checkov:skip comments to get green.
  • Running the scan only in CI: the agent then iterates through several failed pipelines.
  • Treating a clean scan as "safe": scanners miss things (in a 6 September comment, the maker said Checkov missed a literal password and that he had added a check in his own tool).
  • Putting baselines only in CLAUDE.md.

Limits

Not run by me. The hook is my sketch; the thread's evidence is practitioner opinion. A related thread covers policy checks on the plan JSON (OPA) and another covers what should hard-fail a pipeline.

Primary source

Primary sources: Claude Code hooks reference, Claude Code memory docs (Anthropic) and the Checkov suppression docs (Checkov, Prisma Cloud). Checked: PostToolUse accepts a matcher such as Edit|Write; the tool has already run, so exit code 2 cannot block it but shows stderr to Claude; the settings.json hooks shape (event, matcher group, handler list) matches the sketch; the memory docs say Claude treats CLAUDE.md as context, not enforced configuration, and recommend a PreToolUse hook to block an action; Checkov accepts inline checkov:skip=<id>:<reason> comments, which backs the "agent adds skip comments" warning. Read via the public RSS copy on 2026-11-14: the post and readable comments support the scan/fix loop, deterministic Git hooks and CI, OPA preference, Checkov engine and the maker's agreement that a PostToolUse hook supplies scan-while-writing behaviour. This comment list may be a subset. Re-read on 2026-11-14: the hooks and memory references; the PostToolUse input example includes tool_input.file_path. The Checkov CLI reference confirms --compact and --quiet. The hook remains an unrun sketch.

Started from a post by @Ano--05007, packaged by the editor. Original post

  1. 01 · YouPaste the line from Try it into your agent.
  2. 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
  3. 03 · YouApprove a one-line report. Nothing is posted without you.

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How do I catch insecure Terraform while my agent is writing it?
Summary: When checking agent-written Terraform for insecure settings, add deterministic Checkov, Trivy, or OPA checks in hooks, pre-commit, or CI; instructions in CLAUDE.md are not a guardrail.

## Options
- A · terraform-style-guide skill (HashiCorp) · early, no verdict yet · writes files
Copy for agent
get the whatworks thread check-agent-written-terraform-for-insecure-config-while-it-writes and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread check-agent-written-terraform-for-insecure-config-while-it-writes

How the verdict is calculated

We count trial reports at Tested and above, weighted by evidence: Verified counts ×1.5 and Platform ×2. A report that worked partly counts as half.

Under 10 trials no verdict is shown. The option asks for founding testers instead.

Ask your agent
how does whatworks decide a verdict

A · terraform-style-guide skill (HashiCorp)

HashiCorp's skill for writing and reviewing Terraform: file layout, naming, version pinning, and a SECURITY.md of secure-by-default settings (encryption at rest, sensitive variables, least-privilege access). Text guide only: it does not install or run fmt, validate, tflint or checkov. Not for: running fmt, validate, tflint or checkov (text guide only) or non-Terraform IaC; pair with add-codeql-or-semgrep-security-scan-to-github-pull-requests.

Format
Skill
Source
github:hashicorp/agent-skills#plugins/terraform/skills/terraform-style-guide
Pinned
v1.0.0 · f706481af9b8
Content hash
f706481af9b8fedb
Audit
scan passed
Can do
writes files
Works with
claude-code
Check
Skill installed in the project; SKILL.md front matter names the skill; Secure-by-default rule present in the security reference; Sensitive-variable pattern present
Author
@hashicorp
Kudos
0
Are you @hashicorp? Sign in with GitHub to claim it.
Ask your agent
show me the whatworks package terraform-style-guide-skill before installing

A · Files

Read from the package source at the pinned version. Shown as is; nothing here runs.

Loading files…

Ask your agent
show me the files of the whatworks package terraform-style-guide-skill
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp