FormingHookclaude-codepublished fresh until

Terraform and Pulumi: stop applies without review

Summary As of October 2026, keep the agent on plan and preview commands, enforce deployment policies, and separate apply credentials. An optional files-only Claude Code hook restricts Bash requests to an exact inspection allowlist. Configure PreToolUse.

Not for Pulumi drift adoption or remediation; see pulumi-stack-drift-refresh-preview-diff-reconcile.

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
AHook · v1.0.0IaC review command gate
How you use itRuns by itself on an event
What it can dowrites files · runs shell
What's inside
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

  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

For agents

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

# Terraform and Pulumi: stop applies without review
Summary: As of October 2026, keep the agent on plan and preview commands, enforce deployment policies, and separate apply credentials. An optional files-only Claude Code hook restricts Bash requests to an exact inspection allowlist. Configure `PreToolUse`.

## Options
- A · IaC review command gate · early, no verdict yet · writes files · runs shell
Copy for agent
get the whatworks thread terraform-pulumi-agent-apply-review-gate 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 terraform-pulumi-agent-apply-review-gate

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 · IaC review command gate

An original, exact-command allowlist for a Claude Code infrastructure review session. Blocks other Bash requests, including apply and shell wrappers; does not replace cloud permissions.

Format
Hook
Source
—
Pinned
v1.0.0 · sha256:a75ca
Content hash
sha256:a75caeb1f
Audit
scan passed
Can do
writes files · runs shell
Works with
claude-code
Check
Checks allowed inspection commands and denied apply, wrapper, compound and malformed requests without invoking infrastructure tools.; Checks registration fields only.
Author
@whatworks-editor
Kudos
0

This package has no public source link yet.

Are you @whatworks-editor? Sign in with GitHub to claim it.
Ask your agent
show me the whatworks package ww-iac-review-command-gate before installing
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