● Сообщество
nwiizo
⚡ Сразу
tfmcp
автор 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.
Зачем использовать
Ключевые функции
- 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
Живое демо
Как выглядит на практике
Сценарии использования
Реальные сценарии: tfmcp
Когда использовать: A PR changes 40+ resources and you want a sanity check on blast radius before approving.
Предварительные требования
- Terraform CLI installed and cloud credentials configured —
aws configure or equivalent; tfmcp uses whatever your shell has - tfmcp installed via cargo — cargo install tfmcp
Поток
-
Point tfmcp at the Terraform directory
Set TERRAFORM_DIR to ~/work/infra/prod and run terraform plan. Summarize what's changing.✓ Скопировано
→ 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.✓ Скопировано
→ 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.✓ Скопировано
→ Actionable review text ready to paste
Итог: A risk-aware plan review in 3 minutes instead of 30, with no keystrokes spent on apply.
Подводные камни
- 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
Когда использовать: Monthly drift check, or when a cloud console change is suspected.
Поток
-
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.✓ Скопировано
→ 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).✓ Скопировано
→ Two lists: refresh-candidates and re-apply-candidates
Итог: A drift report with specific remediation plan per resource.
Подводные камни
- 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
Когда использовать: You inherited an infra repo and need a map of what's there before touching anything.
Поток
-
Scan the directory
List every module in ~/work/infra. For each, tell me what resources it manages and what inputs it expects.✓ Скопировано
→ 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.✓ Скопировано
→ Clear ASCII tree or numbered list
Итог: A mental map of the repo without having to read every .tf file by hand.
Подводные камни
- Some modules are unused dead code — Ask tfmcp to flag modules referenced nowhere in the root or any other module
Комбинации
Сочетайте с другими MCP — эффект x10
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.✓ Скопировано
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.✓ Скопировано
Стоимость и лимиты
Во что обходится
- Квота API
- No tfmcp-level quota; bounded by your cloud provider API rate limits
- Токенов на вызов
- Plan output for large repos can hit 20k+ tokens — use targeting
- Деньги
- Free and MIT; real cost is whatever apply touches in your cloud
- Совет
- Keep apply off by default. Use
terraform plan -target=module.x to scope noisy plans and save context tokens.
Безопасность
Права, секреты, радиус поражения
Минимальные скоупы: Local terraform binary + cloud-provider read credentials for plan/validate
Хранение учётных данных: Whatever terraform already uses — AWS env vars, ~/.aws/credentials, workload identity, etc.
Исходящий трафик: Calls your cloud provider APIs directly from your machine; tfmcp does not call back home
Никогда не давайте: 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.
Устранение неполадок
Частые ошибки и исправления
terraform binary not found
Install Terraform and ensure it's on PATH. tfmcp shells out to terraform; it does not bundle it.
Проверить: terraform version
Error: No valid credential sources
Your shell's cloud creds aren't exported. Run aws sts get-caller-identity (or equivalent) first.
Проверить: 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.
Проверить: echo $TFMCP_ALLOW_DANGEROUS_OPS
Backend initialization required
Run terraform init once manually in the target dir before calling tfmcp tools.
Проверить: terraform init
Альтернативы
tfmcp в сравнении
| Альтернатива | Когда использовать | Компромисс |
| 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 |