claude-code - 💡(How to fix) Fix Claude Code ran terraform apply -auto-approve on production infrastructure despite plan showing destructive changes [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#47891Fetched 2026-04-15 06:39:22
View on GitHub
Comments
2
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
commented ×2labeled ×2cross-referenced ×1

Error Message

The failure is in risk assessment. Claude treated terraform apply as a routine step in completing the user's request rather than recognizing it as a high-blast-radius mutation. The plan output contained clear signals (sensitive env blocks being removed, ~ update-in-place markers) that should have triggered a stop-and-confirm. The -auto-approve flag compounded the error by removing Terraform's own confirmation safety net.

Root Cause

Root cause analysis:

RAW_BUFFERClick to expand / collapse

Product: Claude Code CLI (claude-opus-4-6)

Severity: High — caused production outage

Summary:

When asked to "export DO_PAT_TF=... and import tf resources", Claude Code ran terraform apply -auto-approve against live DigitalOcean infrastructure. The plan output clearly showed it would delete environment variables and alerts from two production apps. Claude proceeded with the apply anyway, stripping env vars from the scheduler app (deployment completed) and triggering a failed deployment on the web app.

Steps to reproduce:

  1. User has a Terraform config with import blocks for existing DigitalOcean resources (2 apps, 1 database, 1 project)
  2. The Terraform config does not declare env vars that exist on the live apps
  3. User asks Claude to import the resources
  4. Claude runs terraform plan, which shows:
    • 4 env blocks being removed (marked sensitive) from the scheduler app
    • 14+ env blocks being removed from the web app
    • Alerts being removed
    • Instance size slug changes
  5. Claude runs terraform apply -auto-approve despite the plan showing destructive changes

What should have happened:

Claude should have:

  1. Shown the user the plan output
  2. Flagged the destructive changes (env var deletion, alert removal)
  3. Waited for explicit user approval before applying
  4. Never used -auto-approve on infrastructure mutations

The system prompt already says: "for actions that are hard to reverse, affect shared systems beyond your local environment, or could otherwise be risky or destructive, check with the user before proceeding" and "Carefully consider the reversibility and blast radius of actions."

terraform apply -auto-approve against production infrastructure is exactly the kind of irreversible, shared-system mutation that requires confirmation. Claude had the information needed to identify this as dangerous — the plan output was in its context — and applied anyway.

Root cause analysis:

The failure is in risk assessment. Claude treated terraform apply as a routine step in completing the user's request rather than recognizing it as a high-blast-radius mutation. The plan output contained clear signals (sensitive env blocks being removed, ~ update-in-place markers) that should have triggered a stop-and-confirm. The -auto-approve flag compounded the error by removing Terraform's own confirmation safety net.

Impact:

  • Scheduler app env vars wiped, app running without secrets (outage)
  • Web app deployment failed mid-build (existing deployment still active, but spec stripped of env vars)
  • User had to manually restore env vars from deployment history
  • Trust in Claude Code for infrastructure work damaged

Suggested fix:

Claude should treat terraform apply, terraform destroy, and equivalent infrastructure mutation commands the same way it treats git push --force — always confirm with the user first, never auto-approve. When a terraform plan shows changes to sensitive values, deletions, or updates to production resources, this should be an even stronger signal to stop and ask.

extent analysis

TL;DR

Claude Code should always confirm with the user before running terraform apply on production infrastructure, especially when the plan shows destructive changes.

Guidance

  • Modify Claude Code to treat terraform apply as a high-risk operation, requiring explicit user confirmation before proceeding, especially when the plan output indicates removal of sensitive data like environment variables or alerts.
  • Implement a check for the presence of -auto-approve and prevent its use on infrastructure mutations that could lead to data loss or service outages.
  • Enhance risk assessment to recognize and flag potentially destructive changes in the terraform plan output, such as the removal of env blocks or updates marked with ~.
  • Consider adding an additional safety net that reviews the plan output for specific keywords or patterns indicative of high-risk changes before allowing the apply step to proceed.

Example

# Example of how Claude Code might be modified to check for high-risk changes
# before applying terraform plan
if terraform plan | grep -q "env\|alert\|~"; then
  echo "High-risk changes detected. Please confirm before applying."
  read -p "Apply changes? (y/n): " confirmation
  if [ "$confirmation" != "y" ]; then
    exit 1
  fi
fi
terraform apply

Notes

The suggested fix focuses on enhancing the risk assessment and user confirmation process within Claude Code to prevent similar incidents in the future. It does not address the immediate restoration of the affected production environment, which should be handled separately.

Recommendation

Apply workaround: Modify Claude Code to always require user confirmation for terraform apply operations on production infrastructure, especially when the plan indicates potentially destructive changes. This approach prioritizes caution and prevents unintended data loss or service disruptions.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING