Azure Terraform MCP Server
Fetches AzureRM and AzAPI provider documentation, Azure Verified Modules data, and AzAPI examples from GitHub repositories, and clones Azure policy libraries for Conftest validation, using the GitHub API with optional token authentication.
Generates and validates Terraform configurations for Azure: produces aztfexport commands to export Azure resources, resource groups, and query results into Terraform configuration, serves provider and module documentation, and validates Terraform files against Azure security policies using Conftest.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
Azure Terraform MCP Server
A Model Context Protocol (MCP) server that provides AI assistants with comprehensive tools for working with Azure Terraform infrastructure. This server enables AI models to access documentation, export Azure resources, and validate Terraform configurations against Azure policies.
Features
Documentation Tools
AzureRM Provider Documentation - Retrieve comprehensive documentation for any AzureRM resource type, including arguments, attributes, and examples
AzAPI Provider Documentation - Access Azure REST API documentation for AzAPI resources with auto-generated HCL schemas from Bicep type definitions
AzAPI Examples - Fetch Terraform examples for AzAPI resources from the Azure template-reference-generator repository
Azure Verified Modules (AVM) - Browse, search, and retrieve details about Azure Verified Modules including versions, variables, and outputs
Resource Export Tools
Azure Resource Export - Export individual Azure resources to Terraform configuration using aztfexport
Resource Group Export - Export entire resource groups with all contained resources
Query-based Export - Export resources matching Azure Resource Graph queries
Policy Validation Tools
Conftest Integration - Validate Terraform configurations against Azure security policies
AVM Security Policies - Built-in support for Azure Verified Modules security policy sets
Custom Policy Support - Use your own OPA/Rego policies for validation
Automated Conftest Setup - Platform-aware auto-installation of Conftest with intelligent package manager fallbacks (brew, apt, scoop, choco, etc.)
Policy Library Management - Automatic cloning and updating of Azure policy libraries from GitHub
Caching
Unified Cache Management - Persistent cache at
~/.azure-terraform-mcp/for AzAPI schemas, AVM data, conftest policies, and temporary filesAutomatic Expiry - Cached data expires based on configurable TTL (e.g., 5 days for AzAPI schemas, 7 days for temp files)
Telemetry & Monitoring
Azure Application Insights Integration - Built-in telemetry collection for tool usage, performance metrics, and error tracking
Monthly Active Users (MAU) Tracking - Unique user identification and persistence across sessions
Tool Execution Metrics - Automatic tracking of tool call counts, execution duration, and error rates
Configurable Sampling - Control telemetry volume and costs with sampling rates
See Telemetry Setup Guide for details
Related MCP server: Azure Terraform MCP Server
Installation
Prerequisites
Node.js >= 20.0.0
npm or yarn
Optional: aztfexport for resource export functionality
Optional: Conftest for policy validation (can be auto-installed via
setup_conftest_environment)Optional: Terraform for plan generation and export
Install from npm
npm install -g azure-terraform-mcp-serverInstall from source
git clone https://github.com/liuwuliuyun/azure-terraform-mcp-server.git
cd azure-terraform-mcp-server
npm install
npm run buildConfiguration
Environment Variables
Variable | Description | Required |
| GitHub personal access token for API requests (recommended to avoid rate limits) | No |
| Root directory for workspace operations | No |
| Enable debug mode ( | No |
| Azure subscription ID for aztfexport operations | No* |
| Azure tenant ID | No* |
| Azure client/application ID | No* |
| Azure client secret | No* |
| Enable/disable telemetry ( | No |
| Azure Application Insights connection string for telemetry | No |
| Telemetry sampling rate 0.0-1.0 (default: 1.0) | No |
| Flush telemetry on graceful shutdown ( | No |
| Telemetry export interval in milliseconds (default: 300000) | No |
*Required for aztfexport operations
Telemetry: By default, the server collects anonymous usage metrics (tool execution counts, duration, errors) and sends them to Azure Application Insights if a connection string is provided. No personal data is collected. See Telemetry Setup Guide for configuration and privacy details.
MCP Client Configuration
Claude Desktop
Add to your Claude Desktop configuration (claude_desktop_config.json):
{
"mcpServers": {
"azure-terraform": {
"command": "azure-terraform-mcp-server",
"env": {
"GITHUB_TOKEN": "your-github-token"
}
}
}
}VS Code with MCP Extension
Add to your VS Code MCP configuration (.vscode/mcp.json or user settings):
Using global installation:
{
"servers": {
"azure-terraform": {
"command": "azure-terraform-mcp-server",
"env": {
"GITHUB_TOKEN": "${env:GITHUB_TOKEN}"
}
}
}
}Using local development (from source):
{
"servers": {
"azure-terraform": {
"command": "npm",
"args": ["start"],
"cwd": "C:\\path\\to\\azure-terraform-mcp-server",
"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}",
"GITHUB_TOKEN": "${env:GITHUB_TOKEN}"
}
}
}
}Command Generation Approach
The aztfexport and conftest tools use a command generation model rather than direct execution. Instead of running these tools server-side, the MCP server generates the appropriate command with all parameters and returns it to the agent for local execution.
Benefits
Agent Control: The agent (Claude, VS Code, etc.) controls command execution timing and environment
Local Execution: Commands run in the agent's environment with proper dependencies
Better Error Handling: The agent can handle failures and retry with different parameters
Transparency: Full command visibility - agents can inspect, modify, and understand the exact commands being run
Scalability: No long-running processes or resource constraints on the server
How It Works
Generate Command: Call a tool like
generate_aztfexport_resource_commandwith parametersReceive Command Structure: Get back the command, arguments, working directory, and instructions
Execute Locally: The agent runs the command in its environment
Process Results: The agent handles the output files or validation results
Example Flow
Agent → "Generate aztfexport command for resource X"
↓
MCP Server → Returns: { command: "aztfexport", args: [...], notes: [...] }
↓
Agent → Runs: "aztfexport resource X --arg1 value1 ..."
↓
Agent → Processes generated Terraform filesAvailable Tools
Documentation Tools
get_azurerm_provider_documentation
Retrieve documentation for an AzureRM resource type.
Parameters:
resourceTypeName(required): The AzureRM resource type (e.g.,azurerm_virtual_machine)docType(optional):resourceordata-source(default:resource)argumentName(optional): Filter to a specific argumentattributeName(optional): Filter to a specific attribute
Example:
{
"resourceTypeName": "azurerm_storage_account",
"docType": "resource"
}get_azapi_provider_documentation
Retrieve documentation for an AzAPI resource type.
Parameters:
resourceTypeName(required): Azure resource type in REST API format (e.g.,Microsoft.Storage/storageAccounts)apiVersion(optional): Specific API version
list_avm_modules
List all available Azure Verified Modules.
Parameters: None
get_avm_latest_version
Get the latest version of a specific AVM module.
Parameters:
moduleName(required): The module name (e.g.,avm-res-storage-storageaccount)
get_avm_versions
List all versions of a specific AVM module.
Parameters:
moduleName(required): The module name
get_avm_documentation
Get the documentation (README.md) for a specific module version.
Parameters:
moduleName(required): The module namemoduleVersion(required): The version (e.g.,0.1.0)
Resource Export Tools
check_aztfexport_installation
Check if aztfexport and terraform are installed.
Parameters: None
generate_aztfexport_resource_command
Generate an aztfexport command to export a single Azure resource to Terraform configuration. The command is returned for the agent to execute locally.
Parameters:
resourceId(required): Full Azure resource IDoutputFolderName(optional): Output folder nameprovider(optional):azurermorazapi(default:azurerm)resourceName(optional): Custom Terraform resource nameresourceType(optional): Custom Terraform resource typedryRun(optional): Preview without creating files (default:false)includeRoleAssignment(optional): Include role assignments (default:false)parallelism(optional): Parallel operations (1-50, default:10)continueOnError(optional): Continue on errors (default:true)
Returns: Command structure with executable command, arguments, and instructions for local execution
generate_aztfexport_resource_group_command
Generate an aztfexport command to export an entire resource group and all its resources to Terraform configuration. The command is returned for the agent to execute locally.
Parameters:
resourceGroupName(required): Name of the resource groupoutputFolderName(optional): Output folder nameprovider(optional):azurermorazapi(default:azurerm)namePattern(optional): Resource naming patterntypePattern(optional): Resource type filter patterndryRun(optional): Preview without creating filesincludeRoleAssignment(optional): Include role assignmentsparallelism(optional): Parallel operationscontinueOnError(optional): Continue on errors
Returns: Command structure with executable command, arguments, and instructions for local execution
generate_aztfexport_resources_by_query_command
Generate an aztfexport command to export resources matching an Azure Resource Graph query to Terraform configuration. The command is returned for the agent to execute locally.
Parameters:
query(required): Azure Resource Graph query (WHERE clause)outputFolderName(optional): Output folder nameprovider(optional):azurermorazapiOther options same as resource group export
Returns: Command structure with executable command, arguments, and instructions for local execution
Policy Validation Tools
check_conftest_installation
Check if Conftest is installed and get version information.
Parameters:
workspacePath(optional): Path to workspace for policy downloadautoSetup(optional): Enable automatic setup with user confirmation (default:false)
generate_conftest_workspace_validation_command
Generate a conftest command to validate Terraform files in a workspace folder against Azure security policies. The command is returned for the agent to execute locally.
Parameters:
workspaceFolder(required): Path to the workspace folderpolicySet(optional):all,Azure-Proactive-Resiliency-Library-v2, oravmsec(default:all)severityFilter(optional):high,medium,low, orinfocustomPolicies(optional): Comma-separated custom policy paths
Returns: Command structure with executable command, arguments, working directory, and detailed instructions for local execution
generate_conftest_workspace_plan_validation_command
Generate a conftest command to validate Terraform plan files against Azure security policies. The command is returned for the agent to execute locally.
Parameters:
folderName(required): Folder containing the plan filepolicySet(optional): Policy set to useseverityFilter(optional): Severity filtercustomPolicies(optional): Custom policy paths
Returns: Command structure with executable command, arguments, working directory, and detailed instructions for local execution
setup_conftest_environment
Automatically setup Conftest environment: checks installation, installs if needed, downloads policies, and validates everything is working. This is a comprehensive one-step setup that handles platform-aware installation with intelligent fallbacks.
Parameters:
workspacePath(optional): Path to workspace for policy download (defaults to current directory)confirmInstall(optional): User confirmed they want to proceed with installation (default:false)skipPolicies(optional): Skip policy library setup (default:false)
Returns: Setup result with comprehensive status report including:
Installation status and version
Policy library status and available policy sets
Actions taken (installation, policy clone/update)
Restart requirements and next steps
Example Response:
{
"success": true,
"message": "✅ Conftest v0.55.0 | ✅ Policies available (2 sets)",
"conftestInstalled": true,
"conftestVersion": "0.55.0",
"policiesAvailable": true,
"policySets": ["avmsec", "Azure-Proactive-Resiliency-Library-v2"],
"actionsTaken": ["conftest-install", "policy-clone"],
"requiresRestart": false,
"readyToValidate": true
}Library Usage
You can also use this package as a library in your own applications:
import {
createServer,
getAzureRMProviderDocumentation,
getAzAPIProviderDocumentation,
listAvmModules,
generateExportAzureResourceCommand_impl,
generateConftestWorkspaceValidationCommand_impl,
} from 'azure-terraform-mcp-server';
// Get documentation programmatically
const docs = await getAzureRMProviderDocumentation({
resourceTypeName: 'azurerm_storage_account',
docType: 'resource',
});
// Get AzAPI documentation
const azapiDocs = await getAzAPIProviderDocumentation({
resourceTypeName: 'Microsoft.Storage/storageAccounts',
});
// List AVM modules
const modules = await listAvmModules({});
// Generate an aztfexport command
const exportCommand = await generateExportAzureResourceCommand_impl({
resourceId: '/subscriptions/.../resourceGroups/.../providers/...',
provider: 'azurerm',
});
// Generate a conftest command
const conftestCommand = await generateConftestWorkspaceValidationCommand_impl({
workspaceFolder: './terraform',
policySet: 'avmsec',
});Conftest Auto-Setup
The server includes automated Conftest installation and policy management, available via the tools sub-path export:
import {
setupConftestEnvironment,
installConftest,
detectPlatform,
clonePolicyLibrary,
getPolicyStatus,
} from 'azure-terraform-mcp-server/tools';
// Full automated setup (install conftest + download policies)
const result = await setupConftestEnvironment({
workspacePath: './terraform',
confirmInstall: true,
skipPolicies: false,
});
if (result.readyToValidate) {
console.log(`Conftest ${result.conftestVersion} ready`);
}For the full API reference, advanced usage examples, error handling, and troubleshooting, see the Conftest Auto-Setup Guide.
Development
Build
npm run buildWatch mode
npm run devRun tests
# Run unit tests
npm test
# Watch mode for development
npm run test:watch
# Run integration tests
npm run test:integration
# Watch mode for integration tests
npm run test:integration:watch
# Run all tests (unit + integration)
npm run test:allLint
npm run lint
npm run lint:fixType check
npm run typecheckClean build artifacts
npm run cleanArchitecture
src/
├── cli.ts # CLI entry point with graceful shutdown
├── server.ts # MCP server setup and tool registration (14 tools)
├── index.ts # Library exports
├── core/
│ ├── cache-manager.ts # Unified cache management (~/.azure-terraform-mcp/)
│ ├── config.ts # Configuration management and environment variables
│ ├── errors.ts # Custom error classes (7 error types)
│ ├── telemetry.ts # Azure Monitor telemetry (metrics, MAU tracking)
│ ├── types.ts # TypeScript types and Zod schemas (14 param schemas)
│ └── utils.ts # Utility functions (command execution, path resolution)
└── tools/
├── azurerm-docs-provider.ts # AzureRM provider documentation
├── azapi-docs-provider.ts # AzAPI provider documentation
├── azapi-schema-generator.ts # AzAPI schema generation from Bicep types
├── azapi-examples-provider.ts # AzAPI Terraform examples from GitHub
├── avm-docs-provider.ts # Azure Verified Modules documentation
├── aztfexport-runner.ts # Resource export command generation
├── conftest-runner.ts # Policy validation command generation
├── conftest-auto-installer.ts # Platform-aware conftest auto-installation
├── conftest-setup.ts # Conftest setup orchestrator
├── policy-manager.ts # Policy library management (clone/update)
└── index.ts # Tool exportsDocumentation
Conftest Auto-Setup Guide — Detailed API reference, usage examples, error handling, and troubleshooting for the automated Conftest installation and policy management system
Telemetry Setup Guide — Telemetry configuration, metrics reference, Azure Monitor queries, and privacy details
Bug Bash Guide — Step-by-step guide for testing the server with example prompts and scenarios
Contributing
Contributions are welcome! Please read our contributing guidelines and submit pull requests to our repository.
License
MIT License - see LICENSE for details.
Related Projects
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Unified API to query AWS, GCP, Azure and generate Terraform/CLI execution kits for AI agents.
Query your team's drift, vulnerability, and upgrade data from any AI assistant. OAuth 2.1, 51 tools.
Provides capabilities that let LLM agents perform a range of infrastructure management tasks.
Connect AI assistants to your GitHub-hosted Obsidian vault to seamlessly access, search, and analy…
Related MCP Servers
- AlicenseBqualityBmaintenanceProvides comprehensive Terragrunt documentation, configuration generation, and tooling integration for AI assistants, enabling intelligent assistance with Terragrunt configurations, CLI commands, and HCL syntax.87MIT
- AlicenseNot gradedqualityDmaintenanceProvides intelligent assistance for Azure Terraform development, including documentation retrieval, code validation, security scanning, and best practices guidance.1MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to query an approved Terraform module registry and generate compliant Azure infrastructure code. It provides tools for module discovery, scaffolding, and validation against organizational standards.MIT
- FlicenseNot gradedqualityDmaintenanceProvides AI agents with real-time access to live Azure infrastructure, including AKS cluster health, resource management, policy validation, and Terraform analysis through a Model Context Protocol interface.-