npm package: @plugix/mcp-terraform
Description: MCP Server for Terraform - Infrastructure as Code management
Author: Plugix
Latest version: 0.1.0

# @plugix/mcp-terraform

MCP server for Terraform infrastructure management.

## Features

- **get_state** - Get current terraform state summary
- **list_resources** - List all managed resources
- **plan** - Preview infrastructure changes
- **apply** - Apply changes (with confirmation)
- **validate** - Validate configuration files
- **format** - Check or fix file formatting
- **get_outputs** - Get output values
- **init** - Initialize terraform working directory
- **show_resource** - Show detailed resource information

## Installation

```bash
npm install @plugix/mcp-terraform
```

Or run directly:

```bash
npx @plugix/mcp-terraform
```

## Prerequisites

Terraform CLI must be installed and available in PATH:

```bash
# macOS
brew install terraform

# Linux (Ubuntu/Debian)
sudo apt-get install terraform

# Or download from https://www.terraform.io/downloads
```

## Configuration

Set environment variables:

```env
# Plugix API connection
API_URL=wss://api.plugix.ai
API_TOKEN=plx_live_your_token_here

# Terraform settings
TERRAFORM_DIR=/path/to/your/terraform/project  # Default: current directory
TERRAFORM_PATH=terraform                        # Default: terraform
```

## Usage

### Development

```bash
npm run dev
```

### Production

```bash
npm run build
npm start
```

### Docker

```bash
docker build -t plugix-mcp-terraform .
docker run --env-file .env -v /path/to/terraform:/workspace plugix-mcp-terraform
```

### Claude Desktop Integration

Add to `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "terraform": {
      "command": "npx",
      "args": ["@plugix/mcp-terraform"],
      "env": {
        "API_URL": "wss://api.plugix.ai",
        "API_TOKEN": "plx_live_your_token",
        "TERRAFORM_DIR": "/path/to/terraform/project"
      }
    }
  }
}
```

## Tools Reference

### get_state

Get current terraform state summary including all managed resources.

**Parameters:** None

**Example:**

```json
{
  "name": "get_state",
  "arguments": {}
}
```

### list_resources

List all resources currently managed by terraform state.

**Parameters:** None

### plan

Run terraform plan to preview changes.

**Parameters:**

| Name | Type | Description |
|------|------|-------------|
| target | string | Resource address to target (e.g., aws_instance.example) |
| varFile | string | Path to terraform.tfvars file |
| destroy | boolean | Create a destroy plan instead |

**Example:**

```json
{
  "name": "plan",
  "arguments": {
    "target": "aws_instance.web"
  }
}
```

### apply

Apply terraform changes. Requires confirmation.

**Parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| target | string | No | Resource address to target |
| varFile | string | No | Path to terraform.tfvars file |
| confirmed | boolean | Yes | Must be `true` to apply |

**Example:**

```json
{
  "name": "apply",
  "arguments": {
    "confirmed": true
  }
}
```

### validate

Validate terraform configuration files.

**Parameters:** None

**Example:**

```json
{
  "name": "validate",
  "arguments": {}
}
```

### format

Check or fix terraform file formatting.

**Parameters:**

| Name | Type | Description |
|------|------|-------------|
| check | boolean | Only check formatting without changes |
| recursive | boolean | Format files in subdirectories |

**Example:**

```json
{
  "name": "format",
  "arguments": {
    "check": true,
    "recursive": true
  }
}
```

### get_outputs

Get all terraform output values.

**Parameters:** None

### init

Initialize terraform working directory.

**Parameters:**

| Name | Type | Description |
|------|------|-------------|
| upgrade | boolean | Upgrade provider versions |
| reconfigure | boolean | Reconfigure backend |

**Example:**

```json
{
  "name": "init",
  "arguments": {
    "upgrade": true
  }
}
```

### show_resource

Show detailed information about a specific resource.

**Parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| address | string | Yes | Resource address (e.g., aws_instance.example) |

**Example:**

```json
{
  "name": "show_resource",
  "arguments": {
    "address": "aws_instance.web"
  }
}
```

## Workflow Examples

### Check Infrastructure Status

```
1. list_resources  -> See all managed resources
2. get_outputs     -> Get output values
3. validate        -> Check configuration is valid
```

### Make Infrastructure Changes

```
1. plan            -> Preview changes
2. apply (preview) -> Double-check with confirmed=false
3. apply           -> Apply with confirmed=true
4. get_outputs     -> Verify new outputs
```

### Clean Up Infrastructure

```
1. plan (destroy)  -> Preview destroy plan
2. apply           -> Apply destroy with confirmed=true
```

## Security Notes

- The MCP server executes terraform commands locally
- Terraform state files may contain sensitive data
- Use remote backends (S3, GCS, Terraform Cloud) for production
- Credentials are handled by terraform, not this MCP server
- Apply operations require explicit confirmation

## Testing

```bash
npm test
```

## License

MIT