Terraform MCP Server
Manage infrastructure as code with Terraform through your AI assistant - plan, apply, and inspect infrastructure resources.
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
| Tool | Purpose | Category |
|---|---|---|
plan_inspect | Review and summarize terraform plan output | Planning |
state_list | List all resources in terraform state | State |
state_show | Show details of a specific resource | State |
validate_config | Validate terraform configuration files | Config |
drift_detect | Identify resources that drifted from config | Monitoring |
resource_search | Find resources by type, name, or attributes | Discovery |
Common Workflows
Reviewing a Plan Before Apply
- Run
terraform planin your terminal - Use the MCP server to inspect the plan output
- Ask "What resources will be created, modified, and destroyed?"
- Review the natural language summary for potential issues
- Approve or modify the plan based on the analysis
Investigating State Drift
- Connect the MCP server to your terraform state backend
- Run drift detection to compare state against live infrastructure
- Review specific drifted resources with detailed state inspection
- Generate corrective terraform configuration
- Apply fixes through your standard CI/CD pipeline
Generating Configuration from Existing Infrastructure
- Use
resource_searchto find relevant resources in your state - Inspect resource attributes to understand current configuration
- Generate new terraform configuration based on existing patterns
- 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
| Issue | Likely Cause | Solution |
|---|---|---|
| "Plan file not found" | Plan must be generated before inspection | Run terraform plan -out=tfplan first |
| "State locked" | Another process holds the state lock | Check for stuck operations with terraform force-unlock |
| "Provider not configured" | Missing provider configuration | Ensure all required provider blocks exist in your config |
| "Permission denied" | Insufficient backend credentials | Verify AWS/Azure/GCP credentials for your state backend |
Supported Providers
Works with any Terraform provider: AWS, Azure, GCP, Cloudflare, Datadog, Kubernetes, and more.
Related Articles
Firecrawl MCP Server
Firecrawl MCP server provides powerful web scraping, crawling, search, and content extraction capabilities optimized for LLM consumption.
GCP MCP Server
Manage Google Cloud Platform resources through your AI assistant - Compute Engine, Cloud Run, GKE, and more.
Polygon.io MCP Server
Polygon.io MCP server provides real-time and historical stock market data including trades, quotes, aggregates, financials, and options data from the leading market data provider.