# RajeevSirohi/mcp-server-terraform [Health: Active]

**Category:** ☁️ Cloud Platforms  
**Repository:** https://github.com/RajeevSirohi/mcp-server-terraform  
**GitHub Stars:** 1  
**npm Downloads (last month):** 193  
**Views:** 3  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/rajeevsirohi-mcp-server-terraform

## Description
Safety-first Terraform operations: plan/apply/destroy with two-step confirmation gates, plan risk & cost analysis that flags expensive always-on resources (NAT gateways, EKS, Azure Firewall), drift detection, import/taint/refresh, provider auth pre-flight checks, and audit logging.

## Tools
Capabilities this server exposes over MCP:

- **tf_validate** — Validate Terraform configuration files for syntax and internal consistency. Does not access remote state or APIs.
- **tf_plan** — Run terraform plan and return a human-readable diff of what will change. Safe — makes no changes to infrastructure.
- **tf_output** — Read Terraform output values from the current state. Returns all outputs as JSON, or a specific output by name.
- **tf_preflight** — Check which cloud providers are used in a Terraform workspace and verify authentication status for each. Call this before plan or apply to catch credential issues early.
- **tf_drift** — Detect infrastructure drift — resources that were changed outside of Terraform (e.g. manually in the cloud console). Runs a refresh-only plan and reports differences between state and reality. Read-only, makes no changes.
- **tf_apply** — Apply Terraform changes to real infrastructure.

TWO-STEP SAFETY FLOW:
1. Call without confirmed=true → runs terraform plan, shows the diff, returns without applying.
2. Call with confirmed=true after reviewing the diff → actually applies the changes.

Never pass confirmed=true without first showing the plan output to the user.
- **tf_destroy** — Destroy all Terraform-managed infrastructure in the workspace.

TWO-STEP SAFETY FLOW:
1. Call without confirmed=true → shows the destroy plan (what will be deleted).
2. Call with confirmed=true after the user explicitly approves → destroys everything.

This is irreversible. Always show the plan and get explicit user approval first.
- **tf_state** — Manage Terraform state. Supports the following operations:
- list: List all resources in state
- show: Show attributes of a specific resource
- mv: Move/rename a resource in state (use with care)
- rm: Remove a resource from state without destroying it (destructive)
- **tf_resource** — Resource-level state operations:
- import: Bring an existing cloud resource under Terraform management (requires address + id)
- taint: Mark a resource for recreation on next apply (requires address)
- untaint: Remove the taint mark (requires address)
- refresh: Sync state with real infrastructure (accepts drift into state)
- **tf_init** — Initialize a Terraform working directory. Downloads providers and modules. Run this before plan or apply on a fresh workspace.
- **tf_workspace** — Manage Terraform workspaces. Supports:
- list: List all workspaces and show which is active
- show: Show the current workspace name
- select: Switch to a workspace
- new: Create a new workspace

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `npx` (confidence: high):

```json
"mcpServers": {
  "mcp-server-terraform": {
    "command": "npx",
    "args": ["-y","@rajsir/mcp-server-terraform"]
  }
}
```

## Documentation

## What RajeevSirohi/mcp-server-terraform MCP server does

RajeevSirohi/mcp-server-terraform MCP server connects an MCP client to the Terraform CLI installed on the host machine. It lets an agent work with Terraform directories and workspaces through structured tools rather than requiring the user to type each CLI command manually.

The server covers the main workflow from initialization and syntax validation through planning and applying. It also exposes state and workspace operations, output inspection, provider authentication checks, drift detection, and resource actions such as import, taint, untaint, and refresh.

Plan results are analyzed through Terraform’s JSON output. The response summarizes creates, updates, destroys, and replacements, and flags selected resources that can create recurring costs when left running. Examples named by the project include NAT gateways, managed Kubernetes control planes, database services, load balancers, and Azure Firewall.

## How it works

Tool requests are converted into Terraform CLI execution on the local machine. The working directory and other operation parameters are supplied through the MCP tool call, allowing an agent to target a particular configuration or workspace.

The safety model gives `tf_apply` and `tf_destroy` two stages. Without confirmation, the requested operation produces a plan preview and does not change infrastructure. A later call with `confirmed: true` performs the operation. The confirmation requirement is implemented by the server rather than relying only on instructions given to the model.

`tf_drift` uses a refresh-only plan to identify changes made outside Terraform. Its report includes changed attribute names and describes remediation choices. The `tf_preflight` tool checks provider CLI authentication before an operation and can indicate which provider login command is needed.

The project also provides a `/tf-diagnose` prompt for a structured five-step investigation of plan or apply failures. Audit logging is optional; when enabled, each tool call is written as a JSON line containing the time, tool name, result, and duration. Variable values are redacted, while variable names remain visible.

## Setup and configuration

RajeevSirohi/mcp-server-terraform requires Node.js 18 or newer and the Terraform CLI on the system `PATH`.

Claude Desktop can start the server with `npx` and the package name in its MCP configuration. A source checkout can instead be started with `node` and the absolute path to the compiled `dist/index.js` file. The client must be restarted after changing its configuration.

Several environment variables control exposure and logging. `ALLOW_ONLY_READONLY_TOOLS=true` limits availability to validation, planning, and output reading. `ALLOW_ONLY_NON_DESTRUCTIVE_TOOLS=true` blocks apply, destroy, and state move/remove operations. `ALLOWED_TOOLS` accepts an explicit comma-separated tool allowlist. `AUDIT_LOG_PATH` enables JSON-lines audit output at the selected path.

## Tools and capabilities

The available tools are:

- `tf_init` initializes a Terraform working directory.
- `tf_validate` checks configuration syntax.
- `tf_plan` returns a Terraform diff with risk and cost analysis.
- `tf_apply` and `tf_destroy` execute changes only after confirmation.
- `tf_output` reads values from state.
- `tf_state` lists, shows, moves, or removes state entries.
- `tf_workspace` lists, displays, selects, or creates workspaces.
- `tf_preflight` checks provider CLI authentication.
- `tf_drift` searches for changes made outside Terraform.
- `tf_resource` imports, taints, untaints, or refreshes resources.

The project is suited to plan-review-apply workflows, cautious experiments, state inspection, and diagnosing configuration or authentication problems. It can also be configured for shared or sensitive environments where only read-only or explicitly allowed tools should be exposed.

_Full upstream README: https://allmcps.com/mcp/rajeevsirohi-mcp-server-terraform/readme_

