Terraform Plan Analyzer & Risk Assessor
Analyze terraform plan output and produce an AI-powered risk assessment of every infrastructure change — before you press apply.
This skill is STRICTLY READ-ONLY. It runs terraform plan and terraform validate to analyze changes, but it NEVER runs terraform apply, terraform destroy, terraform import, terraform taint, or any command that modifies infrastructure or state.
Activation
This skill activates when the user mentions:
- "terraform plan", "tf plan", "review plan", "plan review"
- "is this plan safe", "safe to apply", "risk assessment"
- "what will be destroyed", "what changes", "terraform changes"
- "terraform state", "state drift", "drift detection"
- "terraform validate", "validate config", "tf validate"
- "IAM changes", "security group changes", "infrastructure changes"
- "blast radius", "cascade effects", "dependencies"
- "tofu plan", "opentofu" (same workflow, different binary)
Example Prompts
- "Review this terraform plan before I apply"
- "What will be destroyed in this plan?"
- "Is this plan safe to apply?"
- "Show me the state drift"
- "What IAM changes are in this plan?"
- "Validate my terraform config in ~/infra/prod"
- "Run a risk assessment on the terraform plan in /deployments/staging"
- "What's the blast radius if I apply this plan?"
Permissions
permissions:
exec: true # Required to run terraform/tofu CLI
read: true # Read .tf files and plan output
write: false # NEVER writes — strictly read-only analysis
network: true # terraform plan needs provider API access
Terraform Change Types — What the Agent Must Know
Understanding Terraform change types is critical for accurate risk assessment:
Action Types (from plan JSON)
| Action |
Meaning |
Risk Profile |
create |
New resource being added |
Generally safe (unless IAM/security) |
update |
Existing resource modified in-place |
Moderate (depends on what's changing) |
delete |
Resource being permanently destroyed |
DANGEROUS — data loss risk |
replace (delete + create) |
Resource must be destroyed and recreated |
DANGEROUS — downtime + data loss |
read |
Data source being refreshed |
Safe (read-only) |
no-op |
No changes needed |
Safe |
What Makes a Change Dangerous
Critical (🔴 CRITICAL):
- Any destroy/replace of: IAM roles/policies, security groups, KMS keys, secrets, databases (RDS, DynamoDB, Cloud SQL, Azure SQL), S3 buckets, DNS records, WAF rules, CloudTrail
- Any update to IAM policies, security group rules, encryption settings
- These changes can cause data loss, security breaches, or service outages
Dangerous (🟠 DANGEROUS):
- Destroy/replace of: EC2 instances, load balancers, ECS/EKS clusters, VPCs, subnets, NAT gateways, Lambda functions, API gateways
- These changes cause downtime and may require manual intervention to recover
Moderate (🟡 MODERATE):
- Updates to: autoscaling policies, monitoring/alerting rules, launch templates
- Creates of: security-sensitive resources (new IAM roles, new security groups)
- Changes that affect capacity or observability but not data integrity
Safe (🟢 SAFE):
- Tag-only updates
- Creating new non-sensitive resources
- No-op / read operations
Replace is Especially Dangerous
When Terraform says it must "replace" a resource, it means:
- Delete the existing resource (irreversible)
- Create a new one with the new configuration
This is triggered when an immutable attribute changes (e.g., changing RDS engine_version, EC2 ami, changing a subnet's AZ). The agent should always flag replaces prominently because:
- The old resource (and its data) is destroyed
- There will be a gap between destroy and create (downtime)
- Dependent resources may break during the transition
Agent Workflow
Follow this sequence exactly based on user intent:
For Plan Analysis ("review this plan", "is it safe", "what changes")
Step 1: Run Plan Analysis
bash <skill_dir>/scripts/tf-plan-review.sh plan <directory>
If no directory specified, use the current working directory.
The script outputs:
- stdout: Structured JSON with all resource changes, risk classifications, and summary
- stderr: Beautiful Markdown risk report
Step 2: Interpret the JSON
Parse the JSON output. Key fields:
{
"overall_risk": "🔴 CRITICAL | 🔴 HIGH | 🟡 MODERATE | 🟢 LOW",
"summary": {
"create": 5,
"update": 3,
"destroy": 1,
"replace": 0
},
"risk_breakdown": {
"critical": 1,
"dangerous": 0,
"moderate": 2,
"safe": 5
},
"resources": [
{
"address": "aws_iam_role.admin",
"action": "delete",
"risk": "🔴 CRITICAL"
}
]
}
Step 3: Present the Risk Assessment
Show the Markdown report from stderr. Then add your own AI analysis:
- Lead with the overall risk level — make it viscerally clear
- Highlight destroys and critical changes first — these are what kill production
- Explain WHY each critical change is dangerous in plain English
- Assess blast radius — what other resources depend on the destroyed ones?
- Present the pre-apply checklist — what should the human verify?
- Give a clear recommendation: "Safe to apply" / "Review needed" / "DO NOT APPLY without ___"
Tone guidance for critical plans:
- Don't be polite about danger. If a plan destroys a production database, say so bluntly.
- "This plan will permanently delete your RDS instance
prod-db. All data will be lost. Do you have a backup?"
- Make the "oh shit" moment impossible to miss.
For State Inspection ("show me state", "what's managed", "state drift")
bash <skill_dir>/scripts/tf-plan-review.sh state "<filter>" <directory>
The filter is optional — it greps resource addresses. Examples:
bash <skill_dir>/scripts/tf-plan-review.sh state "iam" . → all IAM resources
bash <skill_dir>/scripts/tf-plan-review.sh state "aws_instance" . → all EC2 instances
bash <skill_dir>/scripts/tf-plan-review.sh state "" . → all resources
For Validation ("validate config", "check syntax")
bash <skill_dir>/scripts/tf-plan-review.sh validate <directory>
Reports configuration errors and warnings without running a plan.
Environment Variables
| Variable |
Default |
Description |
TF_BINARY |
auto-detect |
Override binary: terraform, tofu, or a path |
TF_PLAN_TIMEOUT |
600 |
Timeout for terraform plan in seconds |
The script auto-detects terraform first, then tofu. Set TF_BINARY=tofu to force OpenTofu.
Error Handling
| Situation |
Behavior |
| terraform/tofu not found |
JSON error with install links for both |
| jq not found |
JSON error with install link |
| No .tf files in directory |
JSON error: "No Terraform configuration files found" |
| Not initialized |
Auto-runs terraform init (for plan) or terraform init -backend=false (for validate) |
| Plan fails (provider errors) |
Extracts error from plan JSON diagnostics, reports it |
| Plan timeout |
Process killed after TF_PLAN_TIMEOUT seconds |
| State not found |
JSON error explaining no state exists |
| Empty state |
Reports "State is empty — no managed resources" |
Safety — CRITICAL RULES
- NEVER run
terraform apply — not even with -auto-approve, not even with -target, not even "just this one resource". NEVER.
- NEVER run
terraform destroy — not under any circumstances.
- NEVER run
terraform import — this modifies state.
- NEVER run
terraform taint or terraform untaint — these modify state.
- NEVER run
terraform state mv, terraform state rm, or terraform state push — these modify state.
- Never expose cloud credentials — if they appear in plan output, redact them.
- Handle sensitive values — Terraform marks values as
(sensitive). Never try to reveal them.
- Never cache or store plan output — plans can contain secrets in resource attributes.
- The ONLY terraform commands this skill runs are:
plan, show, state list, state show, validate, init, providers.
If the user asks you to apply a plan, respond:
"I can analyze and assess Terraform plans, but I cannot apply them. Applying infrastructure changes requires human review and explicit execution. Based on my analysis, here's what you should verify before running terraform apply..."
Common Patterns & Agent Tips
"Is this plan safe to apply?"
Run the plan analysis. If overall_risk is 🟢 LOW:
"This plan looks safe. It creates X new resources with no destroys or security changes. The pre-apply checklist is straightforward."
If overall_risk is 🔴 CRITICAL:
"⚠️ This plan has CRITICAL risk. [Explain specific dangers]. I strongly recommend review by another team member before applying."
"What will be destroyed?"
Run plan, then filter for action == "delete" or action == "replace". Present each with:
- Resource address
- Resource type
- Why it matters (is it stateful? does it have data?)
- What depends on it
"What IAM changes are in this plan?"
Run plan, then filter resources matching IAM patterns. For each:
- What permission is changing
- Is it adding or removing access
- Is it overly permissive (e.g.,
Action: *)
"Show me the blast radius"
Run plan, identify all destroys/replaces, then explain:
- What other resources reference the destroyed ones
- What will break when the resource is gone
- Whether Terraform will auto-fix the dependencies or if manual intervention is needed
Discord v2 Delivery Mode (OpenClaw v2026.2.14+)
When the conversation is happening in a Discord channel:
- Send a compact first summary (overall risk, destroy count, critical resources), then ask if the user wants the full report.
- Keep the first response under ~1200 characters and avoid large Markdown tables in the first message.
- If Discord components are available, include quick actions:
Show Critical Changes
Show Destroyed Resources
Show Pre-Apply Checklist
- If components are not available, provide the same follow-ups as a numbered list.
- Prefer short follow-up chunks (<=15 lines per message) for large plans.
Sensitive Data Handling
Terraform plan JSON may contain sensitive values. The script does NOT extract resource attribute values — it only extracts resource addresses, types, and actions. However, when presenting results:
- Never show attribute values marked
(sensitive) by Terraform
- Never show provider credentials or backend configuration secrets
- If a user asks "what value is changing?", explain that you can see the change type but sensitive values are redacted by Terraform for security
- Never store or cache plan output files
Powered by Anvil AI 🔍
1---
2name: tf-plan-review
3description: >
4 Analyze Terraform plans for risk before you apply. Classifies every change
5 as safe, moderate, dangerous, or critical. Detects destroys, IAM changes,
6 data-loss risks, and blast radius. Entirely read-only — never runs apply.
7version: 0.1.1
8author: Anvil AI
9tags: [terraform, opentofu, iac, infrastructure, devops, risk-assessment, plan-review, security, discord, discord-v2]
10metadata:
11 source: https://skillmd.com/skills/modbender/tf-plan-review
12---
13
14# Terraform Plan Analyzer & Risk Assessor
15
16Analyze `terraform plan` output and produce an AI-powered risk assessment of every infrastructure change — before you press apply.
17
18**This skill is STRICTLY READ-ONLY.** It runs `terraform plan` and `terraform validate` to analyze changes, but it **NEVER** runs `terraform apply`, `terraform destroy`, `terraform import`, `terraform taint`, or any command that modifies infrastructure or state.
19
20## Activation
21
22This skill activates when the user mentions:
23- "terraform plan", "tf plan", "review plan", "plan review"
24- "is this plan safe", "safe to apply", "risk assessment"
25- "what will be destroyed", "what changes", "terraform changes"
26- "terraform state", "state drift", "drift detection"
27- "terraform validate", "validate config", "tf validate"
28- "IAM changes", "security group changes", "infrastructure changes"
29- "blast radius", "cascade effects", "dependencies"
30- "tofu plan", "opentofu" (same workflow, different binary)
31
32## Example Prompts
33
341. "Review this terraform plan before I apply"
352. "What will be destroyed in this plan?"
363. "Is this plan safe to apply?"
374. "Show me the state drift"
385. "What IAM changes are in this plan?"
396. "Validate my terraform config in ~/infra/prod"
407. "Run a risk assessment on the terraform plan in /deployments/staging"
418. "What's the blast radius if I apply this plan?"
42
43## Permissions
44
45```yaml
46permissions:
47 exec: true # Required to run terraform/tofu CLI
48 read: true # Read .tf files and plan output
49 write: false # NEVER writes — strictly read-only analysis
50 network: true # terraform plan needs provider API access
51```
52
53## Terraform Change Types — What the Agent Must Know
54
55Understanding Terraform change types is critical for accurate risk assessment:
56
57### Action Types (from plan JSON)
58
59| Action | Meaning | Risk Profile |
60|--------|---------|-------------|
61| `create` | New resource being added | Generally safe (unless IAM/security) |
62| `update` | Existing resource modified in-place | Moderate (depends on what's changing) |
63| `delete` | Resource being permanently destroyed | **DANGEROUS** — data loss risk |
64| `replace` (`delete` + `create`) | Resource must be destroyed and recreated | **DANGEROUS** — downtime + data loss |
65| `read` | Data source being refreshed | Safe (read-only) |
66| `no-op` | No changes needed | Safe |
67
68### What Makes a Change Dangerous
69
70**Critical (🔴 CRITICAL):**
71- Any destroy/replace of: IAM roles/policies, security groups, KMS keys, secrets, databases (RDS, DynamoDB, Cloud SQL, Azure SQL), S3 buckets, DNS records, WAF rules, CloudTrail
72- Any update to IAM policies, security group rules, encryption settings
73- These changes can cause **data loss**, **security breaches**, or **service outages**
74
75**Dangerous (🟠 DANGEROUS):**
76- Destroy/replace of: EC2 instances, load balancers, ECS/EKS clusters, VPCs, subnets, NAT gateways, Lambda functions, API gateways
77- These changes cause **downtime** and may require manual intervention to recover
78
79**Moderate (🟡 MODERATE):**
80- Updates to: autoscaling policies, monitoring/alerting rules, launch templates
81- Creates of: security-sensitive resources (new IAM roles, new security groups)
82- Changes that affect **capacity** or **observability** but not data integrity
83
84**Safe (🟢 SAFE):**
85- Tag-only updates
86- Creating new non-sensitive resources
87- No-op / read operations
88
89### Replace is Especially Dangerous
90
91When Terraform says it must "replace" a resource, it means:
921. **Delete** the existing resource (irreversible)
932. **Create** a new one with the new configuration
94
95This is triggered when an immutable attribute changes (e.g., changing RDS `engine_version`, EC2 `ami`, changing a subnet's AZ). The agent should **always flag replaces prominently** because:
96- The old resource (and its data) is destroyed
97- There will be a gap between destroy and create (downtime)
98- Dependent resources may break during the transition
99
100## Agent Workflow
101
102Follow this sequence exactly based on user intent:
103
104### For Plan Analysis ("review this plan", "is it safe", "what changes")
105
106#### Step 1: Run Plan Analysis
107
108```bash
109bash <skill_dir>/scripts/tf-plan-review.sh plan <directory>
110```
111
112If no directory specified, use the current working directory.
113
114The script outputs:
115- **stdout:** Structured JSON with all resource changes, risk classifications, and summary
116- **stderr:** Beautiful Markdown risk report
117
118#### Step 2: Interpret the JSON
119
120Parse the JSON output. Key fields:
121
122```json
123{
124 "overall_risk": "🔴 CRITICAL | 🔴 HIGH | 🟡 MODERATE | 🟢 LOW",
125 "summary": {
126 "create": 5,
127 "update": 3,
128 "destroy": 1,
129 "replace": 0
130 },
131 "risk_breakdown": {
132 "critical": 1,
133 "dangerous": 0,
134 "moderate": 2,
135 "safe": 5
136 },
137 "resources": [
138 {
139 "address": "aws_iam_role.admin",
140 "action": "delete",
141 "risk": "🔴 CRITICAL"
142 }
143 ]
144}
145```
146
147#### Step 3: Present the Risk Assessment
148
149Show the Markdown report from stderr. Then add your own AI analysis:
150
1511. **Lead with the overall risk level** — make it viscerally clear
1522. **Highlight destroys and critical changes first** — these are what kill production
1533. **Explain WHY each critical change is dangerous** in plain English
1544. **Assess blast radius** — what other resources depend on the destroyed ones?
1555. **Present the pre-apply checklist** — what should the human verify?
1566. **Give a clear recommendation:** "Safe to apply" / "Review needed" / "DO NOT APPLY without ___"
157
158**Tone guidance for critical plans:**
159- Don't be polite about danger. If a plan destroys a production database, say so bluntly.
160- "This plan will **permanently delete** your RDS instance `prod-db`. All data will be lost. Do you have a backup?"
161- Make the "oh shit" moment impossible to miss.
162
163### For State Inspection ("show me state", "what's managed", "state drift")
164
165```bash
166bash <skill_dir>/scripts/tf-plan-review.sh state "<filter>" <directory>
167```
168
169The filter is optional — it greps resource addresses. Examples:
170- `bash <skill_dir>/scripts/tf-plan-review.sh state "iam" .` → all IAM resources
171- `bash <skill_dir>/scripts/tf-plan-review.sh state "aws_instance" .` → all EC2 instances
172- `bash <skill_dir>/scripts/tf-plan-review.sh state "" .` → all resources
173
174### For Validation ("validate config", "check syntax")
175
176```bash
177bash <skill_dir>/scripts/tf-plan-review.sh validate <directory>
178```
179
180Reports configuration errors and warnings without running a plan.
181
182## Environment Variables
183
184| Variable | Default | Description |
185|----------|---------|-------------|
186| `TF_BINARY` | auto-detect | Override binary: `terraform`, `tofu`, or a path |
187| `TF_PLAN_TIMEOUT` | `600` | Timeout for `terraform plan` in seconds |
188
189The script auto-detects `terraform` first, then `tofu`. Set `TF_BINARY=tofu` to force OpenTofu.
190
191## Error Handling
192
193| Situation | Behavior |
194|-----------|----------|
195| terraform/tofu not found | JSON error with install links for both |
196| jq not found | JSON error with install link |
197| No .tf files in directory | JSON error: "No Terraform configuration files found" |
198| Not initialized | Auto-runs `terraform init` (for plan) or `terraform init -backend=false` (for validate) |
199| Plan fails (provider errors) | Extracts error from plan JSON diagnostics, reports it |
200| Plan timeout | Process killed after TF_PLAN_TIMEOUT seconds |
201| State not found | JSON error explaining no state exists |
202| Empty state | Reports "State is empty — no managed resources" |
203
204## Safety — CRITICAL RULES
205
2061. **NEVER run `terraform apply`** — not even with `-auto-approve`, not even with `-target`, not even "just this one resource". NEVER.
2072. **NEVER run `terraform destroy`** — not under any circumstances.
2083. **NEVER run `terraform import`** — this modifies state.
2094. **NEVER run `terraform taint` or `terraform untaint`** — these modify state.
2105. **NEVER run `terraform state mv`, `terraform state rm`, or `terraform state push`** — these modify state.
2116. **Never expose cloud credentials** — if they appear in plan output, redact them.
2127. **Handle sensitive values** — Terraform marks values as `(sensitive)`. Never try to reveal them.
2138. **Never cache or store plan output** — plans can contain secrets in resource attributes.
2149. The ONLY terraform commands this skill runs are: `plan`, `show`, `state list`, `state show`, `validate`, `init`, `providers`.
215
216If the user asks you to apply a plan, respond:
217> "I can analyze and assess Terraform plans, but I cannot apply them. Applying infrastructure changes requires human review and explicit execution. Based on my analysis, here's what you should verify before running `terraform apply`..."
218
219## Common Patterns & Agent Tips
220
221### "Is this plan safe to apply?"
222Run the plan analysis. If overall_risk is 🟢 LOW:
223> "This plan looks safe. It creates X new resources with no destroys or security changes. The pre-apply checklist is straightforward."
224
225If overall_risk is 🔴 CRITICAL:
226> "⚠️ This plan has CRITICAL risk. [Explain specific dangers]. I strongly recommend review by another team member before applying."
227
228### "What will be destroyed?"
229Run plan, then filter for `action == "delete"` or `action == "replace"`. Present each with:
230- Resource address
231- Resource type
232- Why it matters (is it stateful? does it have data?)
233- What depends on it
234
235### "What IAM changes are in this plan?"
236Run plan, then filter resources matching IAM patterns. For each:
237- What permission is changing
238- Is it adding or removing access
239- Is it overly permissive (e.g., `Action: *`)
240
241### "Show me the blast radius"
242Run plan, identify all destroys/replaces, then explain:
243- What other resources reference the destroyed ones
244- What will break when the resource is gone
245- Whether Terraform will auto-fix the dependencies or if manual intervention is needed
246
247### Discord v2 Delivery Mode (OpenClaw v2026.2.14+)
248
249When the conversation is happening in a Discord channel:
250
251- Send a compact first summary (overall risk, destroy count, critical resources), then ask if the user wants the full report.
252- Keep the first response under ~1200 characters and avoid large Markdown tables in the first message.
253- If Discord components are available, include quick actions:
254 - `Show Critical Changes`
255 - `Show Destroyed Resources`
256 - `Show Pre-Apply Checklist`
257- If components are not available, provide the same follow-ups as a numbered list.
258- Prefer short follow-up chunks (<=15 lines per message) for large plans.
259
260## Sensitive Data Handling
261
262Terraform plan JSON may contain sensitive values. The script does NOT extract resource attribute values — it only extracts resource addresses, types, and actions. However, when presenting results:
263
264- Never show attribute values marked `(sensitive)` by Terraform
265- Never show provider credentials or backend configuration secrets
266- If a user asks "what value is changing?", explain that you can see the change type but sensitive values are redacted by Terraform for security
267- Never store or cache plan output files
268
269## Powered by Anvil AI 🔍