- How you use it
- Runs by itself on an event
- What it can do
- writes files · runs shell
- What's inside
The option
| Option | AHook · v1.0.0IaC review command gate |
|---|---|
| How you use it | Runs by itself on an event |
| What it can do | writes files · runs shell |
| What's inside |
What this thread does
Do first: In a trusted, initialized Terraform project with reviewed provider code and a separate reviewer identity, run terraform plan -out=tfplan.
Keep the agent on plan and preview commands, enforce policy checks in the deployment path, and give apply credentials only to a separate approved executor.
Set up the review boundary
1. Use a trusted checkout and an initialized project. Keep the reviewer identity separate from the identity that can change infrastructure. Plans and previews can execute provider or project code; review that code before granting credentials. 2. For Terraform, capture and inspect the same plan artifact:
terraform plan -out=tfplan
terraform show tfplan
terraform show -json tfplan
Review deletes, replacements, public ingress, identity changes, region and expected resource counts. Keep plan artifacts private. HashiCorp documents saved plans and warns that they can contain sensitive values. Plan reference, plan review tutorial. 3. Make a failing policy block the deployment job. In HCP Terraform, choose the supported policy framework for the workspace or Stack; an agent's written approval is not a policy result. HashiCorp policy overview. 4. For Pulumi, review pulumi preview --diff; use mandatory policy enforcement in the deployment path and protect resources that must not be deleted. Pulumi safeguards. Keep update-plan features out of this baseline. 5. After approval, the separate executor applies the reviewed Terraform artifact. Changed inputs, state, dependencies or code require a new review; do not let the agent generate a fresh unreviewed deployment.
Add the optional command gate
This original files-only example intentionally blocks every Bash command except six exact strings. It does not parse shell syntax or try to enumerate dangerous flags. Other tools, mutable project code, settings edits and external sessions remain outside its boundary. Protect those separately. Python 3 must already exist.
Write .claude/hooks/ww-iac-review.py with this content:
import json
import sys
ALLOWED = {
"terraform fmt -check -recursive",
"terraform validate",
"terraform plan -out=tfplan",
"terraform show tfplan",
"terraform show -json tfplan",
"pulumi preview --diff",
}
def verdict(text):
try:
command = json.loads(text)["tool_input"]["command"]
return 0 if isinstance(command, str) and command in ALLOWED else 2
except (ValueError, KeyError, TypeError):
return 2
if sys.argv[1:] == ["--self-test"]:
for command in ALLOWED:
assert verdict(json.dumps({"tool_input": {"command": command}})) == 0
for command in ["terraform apply tfplan", "pulumi up", "sh -c 'terraform apply'", "terraform validate; terraform apply", "terraform validate\nterraform apply", "env terraform validate"]:
assert verdict(json.dumps({"tool_input": {"command": command}})) == 2
assert verdict("not JSON") == 2
assert verdict("{}") == 2
print("allowlist and denial fixtures passed")
else:
code = verdict(sys.stdin.read())
if code:
print("Review session permits only the exact listed inspection commands.", file=sys.stderr)
sys.exit(code)
Merge this settings-fragment.json content into .claude/settings.json, preserving existing hook entries:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "python3",
"args": [
"${CLAUDE_PROJECT_DIR}/.claude/hooks/ww-iac-review.py"
],
"onFailure": "block"
}
]
}
]
}
}
Claude Code's hooks reference documents the Bash matcher, standard-input payload, blocking exit status and onFailure setting. Start a new session and first request a denied, harmless command such as printf review-gate; confirm it is blocked. From a separate terminal, temporarily move .claude/hooks/ww-iac-review.py out of the way, request the same harmless command, and confirm a hook failure blocks it. Restore the script before continuing. Run the package's self-test from a terminal outside that restricted session. It executes only local fixtures, never the infrastructure commands in those fixtures.
Diagnostic: the agent treats a clean preview as permission to deploy
Require a review record naming the artifact, target account or stack, policy result and intended changes. Withhold apply access even when the command gate passes. An allowlisted command is only eligible to proceed through normal tool permissions.
Versions and evidence
Sources checked 2026-10-28. Releases fetched for this baseline are Terraform 1.17.0, Pulumi 3.272.0 and Claude Code 2.1.312. This is a workflow guide, not an upgrade guide.
Evidence: none found for a public end-to-end trial of this exact command gate. Vendor documentation establishes command semantics, not protection against an agent that can alter its own controls.
Prompt for the agent
Inspect the proposed infrastructure change. Report destructive operations, cost drivers, policy failures and unknown values. Produce a reviewable plan; stop before any deployment or state modification. Never change the review controls to make a command pass.
Limits
The gate checks command text only. It does not audit the executable found on PATH, providers, external data sources, Pulumi programs or other tools. The local fixtures do not prove integration with a running agent. No live infrastructure deployment or policy-service integration is claimed.
Started from a post by @HashiCorp, packaged by the editor. Original post
- 01 · YouPaste the line from Try it into your agent.
- 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
- 03 · YouApprove a one-line report. Nothing is posted without you.