Azure Terraform MCP Server
Provides intelligent assistance for Azure Terraform development, including documentation retrieval, code validation, security scanning, and best practices guidance.
README
Azure Terraform MCP Server
A Model Context Protocol (MCP) server for Azure Terraform operations, providing intelligent assistance for infrastructure as code development with Azure resources.
Overview
This MCP server provides support for Azure Terraform development, including:
- Azure provider documentation retrieval of AzureRM, AzAPI and Azure Verified Module(AVM)
- HCL code validation and static analysis with TFLint
- Security scanning and compliance checking
- Best practices guidance
- Resource analysis and recommendations
Features
š Documentation & Discovery
- Azure Provider Docs: Comprehensive documentation retrieval for AzureRM resources
- AzAPI Schema: Schema lookup for Azure API resources
- Azure Verified Modules (AVM): Discovery and documentation for verified Terraform modules including module listings, versions, variables, and outputs
- Resource Documentation: Detailed arguments, attributes, and examples
š”ļø Security & Compliance
- Security Scanning: Built-in security rule validation for Azure resources
- Azure Verified Modules (AVM) Policies: Integration with Conftest and Azure Policy Library AVM for comprehensive policy validation
- Best Practices: Azure-specific best practices and recommendations
š§ Development Tools
- Unified Terraform Commands: Single tool to execute all Terraform commands (init, plan, apply, destroy, validate, fmt) plus full state management (list, show, mv, rm, pull, push)
- State Management: Safe resource renaming and state manipulation using proper Terraform commands
- HCL Validation: Syntax validation and error reporting for Terraform code
- HCL Formatting: Automatic code formatting for Terraform configurations
- TFLint Integration: Static analysis with TFLint including Azure ruleset support for Terraform workspaces
- Azure Export for Terraform (aztfexport): Export existing Azure resources to Terraform configuration and state
- Code Cleanup Workflow: Transform exported code into production-ready infrastructure as code
š Schema & Provider Analysis
- Terraform Schema Query: Query fine-grained schema information for any Terraform provider
- Provider Item Discovery: List all available resources, data sources, and functions for providers
- Provider Support Discovery: Find which providers are available for analysis
- Dynamic Schema Loading: Support for all providers in the Terraform Registry
š Golang Source Code Analysis
- Golang Namespace Discovery: Find available golang packages for source code analysis
- Version/Tag Support: Query specific versions of provider source code
- Source Code Retrieval: Read golang source code for functions, methods, types, and variables
- Terraform Implementation Analysis: Understand how Terraform resources are implemented in Go
š Integration
- MCP Protocol: Full Model Context Protocol compliance for AI assistant integration
- FastMCP Framework: Built on FastMCP for high-performance async operations
Quick Start
Create or edit .vscode/mcp.json in your workspace:
{
"servers": {
"tf-mcp-server": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"--name", "tf-mcp-server-instance",
"-v", "${workspaceFolder}:/workspace",
"-e", "ARM_CLIENT_ID=${env:ARM_CLIENT_ID}",
"-e", "ARM_CLIENT_SECRET=${env:ARM_CLIENT_SECRET}",
"-e", "ARM_SUBSCRIPTION_ID=${env:ARM_SUBSCRIPTION_ID}",
"-e", "ARM_TENANT_ID=${env:ARM_TENANT_ID}",
"-e", "LOG_LEVEL=INFO",
"ghcr.io/liuwuliuyun/tf-mcp-server:latest"
],
"env": {
"ARM_CLIENT_ID": "${env:ARM_CLIENT_ID}",
"ARM_CLIENT_SECRET": "${env:ARM_CLIENT_SECRET}",
"ARM_SUBSCRIPTION_ID": "${env:ARM_SUBSCRIPTION_ID}",
"ARM_TENANT_ID": "${env:ARM_TENANT_ID}"
}
}
}
}
Need More Options?
For detailed installation instructions including:
- š³ Docker with Azure authentication
- ā” UV installation for development
- š Traditional Python setup
- š§ Optional tool installation
- āļø Configuration options
š See the complete Installation Guide
Configuration
For detailed configuration options including environment variables, configuration files, and Azure authentication setup, see the Installation Guide.
Telemetry
This tool collects anonymous usage telemetry to help improve quality and performance. We collect:
- ā Tool usage counts and performance metrics
- ā Anonymous user ID (randomly generated UUID)
- ā Error types and success rates
We DO NOT collect:
- ā Personal information or identifiers
- ā File paths, resource names, or configuration content
- ā Azure subscription IDs or credentials
Opt-Out
Telemetry is optional and can be disabled anytime:
# Disable telemetry via environment variable
export TELEMETRY_ENABLED=false
Or add to your .vscode/mcp.json:
{
"servers": {
"tf-mcp-server": {
"env": {
"TELEMETRY_ENABLED": "false"
}
}
}
}
š For complete details, see Telemetry Documentation
Available Tools
The server provides comprehensive tools across multiple categories. For complete tool reference with examples, see the API Reference.
Documentation Tools
get_azurerm_provider_documentation: Retrieve specific AzureRM resource or data source documentation with optional argument/attribute lookupget_azapi_provider_documentation: Retrieve AzAPI resource schemas and documentationget_avm_modules: Retrieve all available Azure Verified Modules with descriptions and source informationget_avm_latest_version: Get the latest version of a specific Azure Verified Moduleget_avm_versions: Get all available versions of a specific Azure Verified Moduleget_avm_variables: Retrieve the input variables schema for a specific AVM module versionget_avm_outputs: Retrieve the output definitions for a specific AVM module version
Terraform Command Tools
run_terraform_command: Execute Terraform CLI commands (init, plan, apply, destroy, validate, fmt) and state management operations (list, show, mv, rm, pull, push) inside a workspace folder
Security & Validation Tools
check_conftest_installation: Check Conftest installation status and get version informationrun_conftest_workspace_validation: Validate Terraform files in a workspace folder against Azure security policiesrun_conftest_workspace_plan_validation: Validate Terraform plan files against Azure security policiescheck_tflint_installation: Check TFLint installation status and get version informationrun_tflint_workspace_analysis: Run TFLint static analysis on workspace folders containing Terraform files
Azure Export Tools
check_aztfexport_installation: Check Azure Export for Terraform (aztfexport) installation status and versionexport_azure_resource: Export a single Azure resource to Terraform configuration using aztfexportexport_azure_resource_group: Export an entire Azure resource group and its resources to Terraform configurationexport_azure_resources_by_query: Export Azure resources using Azure Resource Graph queries to Terraform configurationget_aztfexport_config: Get aztfexport configuration settingsset_aztfexport_config: Set aztfexport configuration settings
Coverage Audit Tools
audit_terraform_coverage: Audit Terraform coverage of Azure resources, compare state against Azure Resource Graph to identify gaps, orphaned resources, and get actionable recommendations
Best Practices Tools
get_azure_best_practices: Get comprehensive Azure and Terraform best practices for specific resources and actions- Supports AzureRM 4.x and AzAPI 2.x recommendations
- Special "code-cleanup" action for aztfexport workflow
- Clear guidance on variables vs locals
- State management best practices
- Security hardening recommendations
check_azurerm_feature_availability: Verify if specific features are supported by the AzureRM provider- Guides AI to compare AzureRM and AzAPI documentation
- Recommends using AzAPI when features are missing from AzureRM
š Documentation
For comprehensive guides and examples:
- š Documentation Index - Complete documentation overview
- š Installation Guide - Setup instructions for all platforms
- š§ Configuration Guide - Environment variables and settings
- š API Reference - Complete tool reference with examples
- ā Troubleshooting - Common issues and solutions
Feature Guides
- Azure Documentation Tools - AzureRM, AzAPI, and AVM documentation access
- Terraform Commands - Execute Terraform operations and state management
- Terraform State Management - Safe resource renaming and state operations
- Terraform Coverage Audit - Audit Terraform coverage and identify infrastructure gaps
- Security Policies - Policy-based validation and compliance
- TFLint Integration - Static analysis for Terraform code quality
- Conftest AVM Validation - Policy-based security validation with Azure policies
- Azure Export Integration - Export existing Azure resources to Terraform
- Azure Best Practices - Get Azure-specific recommendations and code cleanup guidance
Example Usage
For complete examples and workflows, see the API Reference.
Project Structure
tf-mcp-server/
āāā src/ # Main source code
ā āāā data/ # Data files and schemas
ā ā āāā azapi_schemas_v2.6.1.json # AzAPI resource schemas
ā āāā tf_mcp_server/ # Core package
ā āāā __init__.py
ā āāā __main__.py # Package entry point
ā āāā launcher.py # Server launcher
ā āāā core/ # Core functionality
ā ā āāā __init__.py
ā ā āāā azapi_schema_generator.py # AzAPI schema generation
ā ā āāā config.py # Configuration management
ā ā āāā models.py # Data models and types
ā ā āāā server.py # FastMCP server with all MCP tools
ā ā āāā terraform_executor.py # Terraform execution utilities
ā ā āāā utils.py # Shared utility functions
ā āāā tools/ # Tool implementations
ā āāā __init__.py
ā āāā avm_docs_provider.py # Azure Verified Modules documentation provider
ā āāā azapi_docs_provider.py # AzAPI documentation provider
ā āāā azurerm_docs_provider.py # AzureRM documentation provider
ā āāā aztfexport_runner.py # Azure Export for Terraform (aztfexport) integration
ā āāā conftest_avm_runner.py # Conftest policy validation runner
ā āāā coverage_auditor.py # Terraform coverage audit tool
ā āāā terraform_runner.py # Terraform command execution and state management
ā āāā tflint_runner.py # TFLint static analysis runner
āāā tests/ # Test suite
ā āāā __init__.py
ā āāā conftest.py # Test configuration
ā āāā test_*.py # Unit tests
ā āāā integration/ # Integration tests
āāā tfsample/ # Sample Terraform configurations
āāā workspace/ # Default workspace directory for operations
āāā policy/ # Security and compliance policies
ā āāā avmsec/ # Azure security policies (AVM Security)
ā āāā Azure-Proactive-Resiliency-Library-v2/ # Azure resiliency policies
ā āāā common/ # Common policy utilities
āāā docs/ # Comprehensive documentation
āāā examples/ # Usage examples and workflows
āāā pyproject.toml # Project configuration (UV/pip)
āāā uv.lock # UV dependency lockfile
āāā Dockerfile # Docker container configuration
āāā docker-compose.yml # Docker Compose setup
āāā README.md # This file
āāā CONTRIBUTE.md # Development and contribution guide
Troubleshooting
For comprehensive troubleshooting including:
- Docker and VS Code MCP setup issues
- Azure authentication problems
- Tool installation and configuration
- Performance optimization
- Platform-specific solutions
š See the detailed Troubleshooting Guide
Quick Debug
Enable debug logging:
{
"mcpServers": {
"tf-mcp-server": {
"command": "docker",
"args": [
"run", "--rm", "-i",
"-v", "${workspaceFolder}:/workspace",
"-e", "LOG_LEVEL=DEBUG",
"-e", "MCP_DEBUG=true",
"ghcr.io/liuwuliuyun/tf-mcp-server:latest"
]
}
}
}
Check logs for detailed information and error diagnosis.
Contributing
We welcome contributions! For development setup, coding standards, and detailed contribution guidelines:
š See the complete Contributing Guide
Quick Start for Contributors
- Fork the repository
- Set up development environment (see CONTRIBUTE.md)
- Create a feature branch:
git checkout -b feature/your-feature - Make changes with tests
- Run tests and formatting:
pytest && black src/ tests/ - Submit a pull request
License
This project is licensed under the MIT License. See LICENSE file for details.
Support
For issues and questions:
- Create an issue in the repository
- Check the troubleshooting section above
- Review existing documentation and tests
Related Projects
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.