Terraform MCP Server

Manage infrastructure as code with Terraform through your AI assistant - plan, apply, and inspect infrastructure resources.

April 14, 2026
MCP ServerDevelopment Tools & DevOpsTerraform MCP Server

Terraform MCP Server

Manage Terraform infrastructure directly from your AI assistant. The Terraform MCP server bridges AI assistants with your infrastructure-as-code workflows, enabling natural language interactions for planning, applying, and inspecting Terraform-managed resources across any supported provider.

This server is ideal for DevOps engineers who want to review plan outputs conversationally, SREs who need quick state inspections during incidents, and platform teams managing multi-provider infrastructure at scale.

What it Does

  • Plan Inspection: Review terraform plan output in natural language
  • State Management: List and inspect resources in terraform state
  • Configuration Help: Generate and validate Terraform configurations
  • Resource Queries: Find resources by type, name, or attributes
  • Drift Detection: Identify resources that have drifted from configuration

Installation

# Using npx
npx -y @anthropic-ai/mcp-server-terraform

# Using Docker
docker run -i --rm -v $(pwd):/workspace mcp/terraform

Configuration

{
  "mcpServers": {
    "terraform": {
      "command": "npx",
      "args": ["-y", "@anthropic-ai/mcp-server-terraform"],
      "env": {
        "TF_WORKSPACE": "production"
      }
    }
  }
}

Available Tools

ToolPurposeCategory
plan_inspectReview and summarize terraform plan outputPlanning
state_listList all resources in terraform stateState
state_showShow details of a specific resourceState
validate_configValidate terraform configuration filesConfig
drift_detectIdentify resources that drifted from configMonitoring
resource_searchFind resources by type, name, or attributesDiscovery

Common Workflows

Reviewing a Plan Before Apply

  1. Run terraform plan in your terminal
  2. Use the MCP server to inspect the plan output
  3. Ask "What resources will be created, modified, and destroyed?"
  4. Review the natural language summary for potential issues
  5. Approve or modify the plan based on the analysis

Investigating State Drift

  1. Connect the MCP server to your terraform state backend
  2. Run drift detection to compare state against live infrastructure
  3. Review specific drifted resources with detailed state inspection
  4. Generate corrective terraform configuration
  5. Apply fixes through your standard CI/CD pipeline

Generating Configuration from Existing Infrastructure

  1. Use resource_search to find relevant resources in your state
  2. Inspect resource attributes to understand current configuration
  3. Generate new terraform configuration based on existing patterns
  4. Validate the configuration before applying

Example Prompts

  • "Show me all resources in the current terraform state"
  • "What would happen if I apply these changes?"
  • "Generate a terraform configuration for an S3 bucket"
  • "Check for drift in our AWS resources"
  • "List all EC2 instances managed by terraform"
  • "Compare the plan output with the current state for any discrepancies"

Troubleshooting

IssueLikely CauseSolution
"Plan file not found"Plan must be generated before inspectionRun terraform plan -out=tfplan first
"State locked"Another process holds the state lockCheck for stuck operations with terraform force-unlock
"Provider not configured"Missing provider configurationEnsure all required provider blocks exist in your config
"Permission denied"Insufficient backend credentialsVerify AWS/Azure/GCP credentials for your state backend

Supported Providers

Works with any Terraform provider: AWS, Azure, GCP, Cloudflare, Datadog, Kubernetes, and more.