SuperAPIAI Directory

mcp-server-terraform

github.com · AI developer platforms

Terraform operations with two-step confirmation for plan/apply/destroy, plan risk and cost analysis, drift detection, import/taint/refresh and audit logging.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)
PlatformsmacOS · Linux

About this tool

mcp-server-terraform is a Model Context Protocol (MCP) server that lets Claude manage Terraform infrastructure through natural language, allowing you to run plan, apply changes, inspect state, and diagnose failures within a Claude conversation without switching to a terminal. The server translates natural language requests into terraform CLI commands that are actually executed on the user's machine, and triggers a built-in safety confirmation flow before any destructive operation is performed.

Purpose and main capabilities Plan risk and cost summary: every plan (and every apply preview) is analyzed via terraform show -json and accompanied by a structured summary—resources that will be destroyed are flagged separately, and persistent resources that could cause bill shock are given a rough monthly cost. Resource types that get cost warnings include NAT gateways, load balancers, EKS/AKS/GKE control planes, RDS/Cloud SQL instances, ElastiCache, Redshift, MSK, and Azure Firewall (about $900 per month). Drift detection: tf_drift runs a refresh-only plan, reporting resources that were modified outside Terraform (for example, manually in the cloud console), giving the names of the changed attributes and remediation options. Audit log: after setting AUDIT_LOG_PATH to a file path, every tool call is appended as a JSON line record including timestamp, tool name, result, and duration. Variable values are always redacted (for example, db_password=<redacted>), and only names are logged. Confirmation flow: tf_apply and tf_destroy use a two-step safety flow. The first call (without confirmed) runs terraform plan and shows the diff, doing nothing else; the second call (confirmed: true) actually applies or destroys. Claude is instructed never to pass confirmed: true before first showing you the plan. This two-step gate is built into the server itself, not just at the prompt level, so Claude cannot skip it. Diagnostic prompts: the server provides a /tf-diagnose prompt that guides Claude through a systematic 5-step diagnosis of a plan or apply failure; there is also /tf-login for step-by-step authentication setup per provider.

How to use Prerequisites: Node.js 18 or later, the Terraform CLI available in PATH, and Claude Desktop (or any MCP-compatible client). No installation is required; you can run it directly from npm, or from source for development. Claude Desktop configuration: add the configuration to the Claude Desktop config file—macOS: ~/Library/Application Support/Claude/claude_desktop_config.json; Windows: %APPDATA%\Claude\claude_desktop_config.json. If running from source, use "command": "node" and "args": ["/absolute/path/to/dist/index.js"]. After restarting Claude Desktop, you should see a hammer icon indicating the tools are available. Once connected, you can talk to Claude about Terraform workspaces in natural language, for example: "Plan the changes in /infra/staging and explain what will change", "Apply it — but only if no resources will be destroyed", "Show me all the outputs from the prod workspace", "Something broke after the last apply — diagnose it". The first time you enter a new workspace, you can have Claude run tf_init, then tf_preflight; if you are not authenticated, it will tell you the specific command you need to run (az login, aws configure, etc.). Common loop: plan → review → apply. After requesting a plan, you get a diff and summary (counts of create/update/destroy, destructive operations clearly flagged, cost warnings for expensive persistent resources); say "Looks good, applAfter "y it", Claude will show a plan preview again and request confirmation; it will only be applied if you agree. Infrastructure checks: you can ask whether anyone has made changes in the prod workspace outside of terraform (tf_drift compares state with the actual situation, reports what was changed in the console, and provides options to accept or roll back); you can also ask Claude to show outputs, list state contents, and list workspaces. Learning/experimental scenarios: for example, have Claude apply a certain VPC experiment and destroy everything when you say done; cost tagging is especially useful here. Import and taint: you can request importing existing resources into state (such as importing my-legacy-bucket as aws_s3_bucket.legacy), or taint a web server so that it is rebuilt on the next apply.

Safe mode and recommended configuration Available tools can be controlled via environment variables. For shared or cautious environments, it is recommended to run with ALLOW_ONLY_NON_DESTRUCTIVE_TOOLS=true, making apply/destroy completely unavailable, and set AUDIT_LOG_PATH to record every operation.

Development and extension How to add a new tool: create src/tools/tf-yourcommand.ts, export the *Schema constant and an async handler function; import both in src/index.ts; add the schema to the readonlyTools or destructiveTools array; add a branch in the switch of the CallToolRequestSchema handler.

Limitations and not yet provided The material only lists future plans (Terraform Cloud / Enterprise API support as Phase 2, OpenTelemetry tracing, SSE/streaming HTTP transport for remote deployment, Docker images on GitHub Container Registry, import/taint/untaint/refresh, CI builds and an e2e test matrix with real terraform, etc.); these have not yet been implemented, and specific details are not yet provided. The license is MIT.

Up/Down to navigate · Enter to open · ESC to closeBrowse all tools