● Community
nwiizo
⚡ Instant
tfmcp
by nwiizo · nwiizo/tfmcp
Let Claude read your Terraform configs, dry-run plans, and (opt-in) apply changes — without handing over your cloud keys.
tfmcp wraps the local Terraform CLI as an MCP server. It reads HCL, runs plan/validate/format, explores state, and — only when you explicitly enable TFMCP_ALLOW_DANGEROUS_OPS — can apply or destroy. Credentials stay in your existing AWS/GCP/Azure env; tfmcp never sees them directly.
Why use it
Key features
- 31 tools covering init, plan, apply, destroy, validate, state, workspaces, modules
- Plan analysis with risk scoring and state drift detection
- Dangerous ops gated behind TFMCP_ALLOW_DANGEROUS_OPS env var (off by default)
- Audit logging on by default — every tool call recorded
- Uses your local terraform binary and existing provider credentials
Live Demo
What it looks like in practice
Use Cases
Real-world ways to use tfmcp
When to use: A PR changes 40+ resources and you want a sanity check on blast radius before approving.
Prerequisites
- Terraform CLI installed and cloud credentials configured —
aws configure or equivalent; tfmcp uses whatever your shell has - tfmcp installed via cargo — cargo install tfmcp
Flow
-
Point tfmcp at the Terraform directory
Set TERRAFORM_DIR to ~/work/infra/prod and run terraform plan. Summarize what's changing.✓ Copied
→ Clean plan summary with add/change/destroy counts
-
Ask for a risk-scored breakdown
For every resource being destroyed or replaced, rate the risk (low/med/high) and explain why. Flag anything stateful.✓ Copied
→ Risk table highlighting DB, queue, or data resources
-
Get a PR-ready review comment
Draft a PR review comment: approve, request changes, or block — with reasoning.✓ Copied
→ Actionable review text ready to paste
Outcome: A risk-aware plan review in 3 minutes instead of 30, with no keystrokes spent on apply.
Pitfalls
- Plan succeeds locally but will fail in CI due to different provider versions — Make sure tfmcp's terraform version matches what your CI uses — pin via .terraform-version or tfenv
- State is remote and tfmcp gets stuck on auth — Run
terraform init once manually to cache backend creds before invoking tfmcp
When to use: Monthly drift check, or when a cloud console change is suspected.
Flow
-
Run a plan against prod and look for changes
Run terraform plan against prod and tell me if there's drift — resources where the real state diverges from .tf.✓ Copied
→ List of drifted resources with diffs
-
Classify each drift
For each drift, say whether it's safe to refresh (reconcile Terraform to reality) or requires re-apply (reconcile reality to Terraform).✓ Copied
→ Two lists: refresh-candidates and re-apply-candidates
Outcome: A drift report with specific remediation plan per resource.
Pitfalls
- Drift is normal for some auto-scaled or provider-managed fields — Add a drift-ignore list (via ignore_changes lifecycle block) for known-noisy fields like last_modified timestamps
When to use: You inherited an infra repo and need a map of what's there before touching anything.
Flow
-
Scan the directory
List every module in ~/work/infra. For each, tell me what resources it manages and what inputs it expects.✓ Copied
→ Module inventory with purpose and inputs per module
-
Generate a dependency graph
Run terraform graph and describe the module dependency tree — which modules depend on which.✓ Copied
→ Clear ASCII tree or numbered list
Outcome: A mental map of the repo without having to read every .tf file by hand.
Pitfalls
- Some modules are unused dead code — Ask tfmcp to flag modules referenced nowhere in the root or any other module
Combinations
Pair with other MCPs for X10 leverage
Review a Terraform PR end-to-end: pull diff from GitHub, plan locally via tfmcp, post review comment
Fetch PR #42 from acme/infra, checkout the branch, run tfmcp terraform plan, and draft a review comment.✓ Copied
Bulk-refactor HCL files and verify the plan doesn't change output
Rename variable aws_region to region across all .tf files in ~/infra, then confirm plan shows no resource changes.✓ Copied
Cost & Limits
What this costs to run
- API quota
- No tfmcp-level quota; bounded by your cloud provider API rate limits
- Tokens per call
- Plan output for large repos can hit 20k+ tokens — use targeting
- Monetary
- Free and MIT; real cost is whatever apply touches in your cloud
- Tip
- Keep apply off by default. Use
terraform plan -target=module.x to scope noisy plans and save context tokens.
Security
Permissions, secrets, blast radius
Minimum scopes: Local terraform binary + cloud-provider read credentials for plan/validate
Credential storage: Whatever terraform already uses — AWS env vars, ~/.aws/credentials, workload identity, etc.
Data egress: Calls your cloud provider APIs directly from your machine; tfmcp does not call back home
Never grant: TFMCP_ALLOW_DANGEROUS_OPS=true in shared sessions Admin cloud credentials when read-only would suffice
- This is an experimental tool — pin a specific version and test in a non-prod workspace first.
- Leave TFMCP_ALLOW_DANGEROUS_OPS unset until you trust your prompts.
Troubleshooting
Common errors and fixes
terraform binary not found
Install Terraform and ensure it's on PATH. tfmcp shells out to terraform; it does not bundle it.
Verify: terraform version
Error: No valid credential sources
Your shell's cloud creds aren't exported. Run aws sts get-caller-identity (or equivalent) first.
Verify: aws sts get-caller-identity
Plan says 'apply denied: TFMCP_ALLOW_DANGEROUS_OPS not set'
By design. If you truly want to apply, export TFMCP_ALLOW_DANGEROUS_OPS=true for that session only.
Verify: echo $TFMCP_ALLOW_DANGEROUS_OPS
Backend initialization required
Run terraform init once manually in the target dir before calling tfmcp tools.
Verify: terraform init
Alternatives
tfmcp vs others
| Alternative | When to use it instead | Tradeoff |
| terraform-mcp-server (hashicorp official) | You want a vendor-backed MCP with registry support | Less CLI parity; fewer state/drift tools |
| Raw shell MCP + terraform | You want total flexibility | No guardrails — easy to run terraform destroy by accident |