mcp-terraform-assistant
An MCP server for managing infrastructure as code using Terraform
Documentation
MCP Infrastructure as Code Assistant
An MCP server for managing infrastructure as code with Terraform.
Features
- Initialize Terraform working directories
- Generate and show execution plans
- Apply changes to infrastructure
- Destroy infrastructure
- Validate Terraform configurations
- Show current state or saved plans
- Manage Terraform workspaces
Prerequisites
- Python 3.8 or higher
- Terraform 1.5.7 or higher
- Docker and Docker Compose (optional)
Installation
Local Installation
1. Clone the repository:
git clone https://github.com/yourusername/mcp-iac.git
cd mcp-iac2. Install dependencies using uv:
curl -LsSf https://astral.sh/uv/install.sh | sh
uv pip install -e .Docker Installation
1. Clone the repository:
git clone https://github.com/yourusername/mcp-iac.git
cd mcp-iac2. Build and run the Docker container:
docker-compose up -dUsage
Local Usage
1. Start the MCP server:
python main.py2. Use the MCP CLI to interact with the server:
mcp terraform_init --working-dir ./terraform
mcp terraform_plan --working-dir ./terraform
mcp terraform_apply --working-dir ./terraform --auto-approveDocker Usage
1. Start the MCP server:
docker-compose up -d2. Use the MCP CLI to interact with the server:
mcp terraform_init --working-dir ./terraform
mcp terraform_plan --working-dir ./terraform
mcp terraform_apply --working-dir ./terraform --auto-approveExample Terraform Configuration
The repository includes an example Terraform configuration that creates an EC2 instance in AWS:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = var.region
}
resource "aws_instance" "example" {
ami = var.ami_id
instance_type = var.instance_type
tags = {
Name = var.instance_name
}
}Contributing
1. Fork the repository
2. Create a feature branch
3. Commit your changes
4. Push to the branch
5. Create a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Available Tools
- `terraform_init`: Initialize a Terraform working directory
- `terraform_plan`: Generate and show an execution plan for Terraform
- `terraform_apply`: Apply the changes required to reach the desired state
- `terraform_destroy`: Destroy the infrastructure managed by Terraform
- `terraform_validate`: Validate the syntax and internal consistency of Terraform files
- `terraform_show`: Show the current state or a saved plan
- `terraform_workspace_list`: List Terraform workspaces
- `terraform_workspace_select`: Select a Terraform workspace
Example Usage
Here's an example of how to use the MCP server with an AI agent:
1. Start the MCP server:
python main.py2. Connect to the server using an MCP client:
mcp connect http://localhost:80003. The AI agent can now help you with Terraform operations. For example:
Examples
Check out the `examples` directory for sample Terraform configurations that demonstrate how to use the MCP server:
- `examples/aws-s3`: A simple AWS S3 bucket example
Frequently asked questions
What is mcp-terraform-assistant?
mcp-terraform-assistant is An MCP server for managing infrastructure as code using Terraform
How do I install mcp-terraform-assistant?
Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.
Is mcp-terraform-assistant open source?
Yes — it is hosted on GitHub at https://github.com/guilhermeyoshida/mcp-terraform-assistant and has 1 stars.
Related MCP tools
Damn Vulnerable MCP Server Python-based implementation. Trusted by 1200+ developers. Trusted by 1200+ developers. Trusted by 1200+ developers.
A Model Context Protocol (MCP) server that enables secure interaction with MySQL databases Python-based implementation. Trusted by 900+ developers.
Query MCP enables end-to-end management of Supabase via chat interface: read & write query executions, management API support, automatic migration versioning...
Model Context Protocol with Neo4j Python-based implementation. Trusted by 700+ developers. Trusted by 700+ developers. Trusted by 700+ developers.
An MCP server that provides control over Android devices via adb Python-based implementation. Trusted by 500+ developers.
A Model Context Protocol (MCP) server for PostgreSQL databases with enhanced capabilities for AI agents. Python-based implementation.
Run your own MCP server? See who uses it and what to fix.
Measure it with TrackMCP