Official HashiCorp Terraform MCP server
## Terraform MCP Server: Infrastructure as Code The **Terraform MCP Server** integrates HashiCorp Terraform into Google Antigravity, enabling infrastructure provisioning, state management, and multi-cloud resource orchestration directly from your development environment. ### Why Terraform MCP? - **Multi-Cloud Support**: Manage AWS, Azure, GCP, and 1000+ providers with unified syntax - **State Management**: Track infrastructure state with remote backends and locking - **Plan Preview**: Preview changes before applying to catch issues early - **Drift Detection**: Identify configuration drift between desired and actual state - **Module Ecosystem**: Leverage community modules for common infrastructure patterns ### Key Features #### 1. Plan and Apply ```python # Initialize Terraform configuration await mcp.init(working_dir="/infra/production") # Generate execution plan plan = await mcp.plan( working_dir="/infra/production", var={"environment": "prod", "region": "us-east-1"} ) print(f"Resources to add: {plan['add']}") print(f"Resources to change: {plan['change']}") print(f"Resources to destroy: {plan['destroy']}") # Apply changes result = await mcp.apply( working_dir="/infra/production", auto_approve=False # Require confirmation ) ``` #### 2. State Operations ```python # List resources in state resources = await mcp.state_list(working_dir="/infra/production") for resource in resources: print(f"Resource: {resource}") # Show resource details details = await mcp.state_show( working_dir="/infra/production", address="aws_instance.web" ) print(details) # Import existing resources await mcp.import_resource( address="aws_s3_bucket.data", id="my-existing-bucket" ) ``` #### 3. Workspace Management ```python # List workspaces workspaces = await mcp.workspace_list(working_dir="/infra") print(f"Workspaces: {workspaces}") # Create and switch workspace await mcp.workspace_new(name="staging") await mcp.workspace_select(name="staging") # Current workspace current = await mcp.workspace_show() ``` #### 4. Output and Validation ```python # Get output values outputs = await mcp.output(working_dir="/infra/production") print(f"VPC ID: {outputs['vpc_id']['value']}") print(f"Load Balancer DNS: {outputs['lb_dns']['value']}") # Validate configuration validation = await mcp.validate(working_dir="/infra/production") if not validation["valid"]: for error in validation["diagnostics"]: print(f"Error: {error['summary']}") ``` ### Configuration ```json { "mcpServers": { "terraform": { "command": "npx", "args": ["-y", "@anthropic/mcp-terraform"], "env": { "TF_CLI_CONFIG_FILE": "~/.terraformrc", "AWS_ACCESS_KEY_ID": "your-aws-key", "AWS_SECRET_ACCESS_KEY": "your-aws-secret", "TF_VAR_environment": "development" } } } } ``` ### Use Cases **Infrastructure Provisioning**: Create and manage cloud resources like VPCs, compute instances, databases, and load balancers. **Environment Replication**: Use workspaces to manage identical infrastructure across development, staging, and production. **Compliance Automation**: Enforce infrastructure policies using Sentinel or OPA integration with plan validation. **Disaster Recovery**: Document and recreate infrastructure from code during DR scenarios with version-controlled configurations. The Terraform MCP enables infrastructure as code management directly within your Google Antigravity development environment.
{
"mcpServers": {
"terraform": {
"mcpServers": {
"terraform": {
"args": [
"-y",
"@hashicorp/terraform-mcp-server"
],
"command": "npx"
}
}
}
}
}