MCP Server for Terraform - Infrastructure as Code management
npm install @plugix/mcp-terraformMCP server for Terraform infrastructure management.
- 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
``bash`
npm install @plugix/mcp-terraform
Or run directly:
`bash`
npx @plugix/mcp-terraform
Terraform CLI must be installed and available in PATH:
`bashmacOS
brew install terraform
Configuration
Set environment variables:
`env
Plugix API connection
API_URL=wss://api.plugix.ai
API_TOKEN=plx_live_your_token_hereTerraform settings
TERRAFORM_DIR=/path/to/your/terraform/project # Default: current directory
TERRAFORM_PATH=terraform # Default: terraform
`Usage
$3
`bash
npm run dev
`$3
`bash
npm run build
npm start
`$3
`bash
docker build -t plugix-mcp-terraform .
docker run --env-file .env -v /path/to/terraform:/workspace plugix-mcp-terraform
`$3
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
$3
Get current terraform state summary including all managed resources.
Parameters: None
Example:
`json
{
"name": "get_state",
"arguments": {}
}
`$3
List all resources currently managed by terraform state.
Parameters: None
$3
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"
}
}
`$3
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
}
}
`$3
Validate terraform configuration files.
Parameters: None
Example:
`json
{
"name": "validate",
"arguments": {}
}
`$3
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
}
}
`$3
Get all terraform output values.
Parameters: None
$3
Initialize terraform working directory.
Parameters:
| Name | Type | Description |
|------|------|-------------|
| upgrade | boolean | Upgrade provider versions |
| reconfigure | boolean | Reconfigure backend |
Example:
`json
{
"name": "init",
"arguments": {
"upgrade": true
}
}
`$3
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
$3
`
1. list_resources -> See all managed resources
2. get_outputs -> Get output values
3. validate -> Check configuration is valid
`$3
`
1. plan -> Preview changes
2. apply (preview) -> Double-check with confirmed=false
3. apply -> Apply with confirmed=true
4. get_outputs -> Verify new outputs
`$3
`
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
``MIT