Cover image
Try Now
2025-04-08

用于使用Terraform将基础架构管理为代码的MCP服务器

3 years

Works with Finder

1

Github Watches

0

Github Forks

0

Github Stars

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-iac
    
  2. 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-iac
    
  2. Build and run the Docker container:

    docker-compose up -d
    

Usage

Local Usage

  1. Start the MCP server:

    python main.py
    
  2. 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-approve
    

Docker Usage

  1. Start the MCP server:

    docker-compose up -d
    
  2. 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-approve
    

Example 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.py
    
  2. Connect to the server using an MCP client:

    mcp connect http://localhost:8000
    
  3. The AI agent can now help you with Terraform operations. For example:

    • Initialize a Terraform working directory
    • Generate and review execution plans
    • Apply changes to infrastructure
    • Destroy infrastructure resources
    • Validate Terraform configurations

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

相关推荐

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • pontusab
  • 光标与风浪冲浪社区,查找规则和MCP

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

  • ravitemer
  • 一个功能强大的Neovim插件,用于管理MCP(模型上下文协议)服务器

  • patruff
  • Ollama和MCP服务器之间的桥梁,使本地LLMS可以使用模型上下文协议工具

  • av
  • 毫不费力地使用一个命令运行LLM后端,API,前端和服务。

  • Mintplex-Labs
  • 带有内置抹布,AI代理,无代理构建器,MCP兼容性等的多合一桌面和Docker AI应用程序。

  • appcypher
  • 很棒的MCP服务器 - 模型上下文协议服务器的策划列表

  • 1Panel-dev
  • 🔥1Panel提供了直观的Web接口和MCP服务器,用于在Linux服务器上管理网站,文件,容器,数据库和LLMS。

    Reviews

    5 (1)
    Avatar
    user_cFCj9opy
    2025-04-18

    As a dedicated user of the mcp-terraform-assistant by guilhermeyoshida, I find this tool incredibly useful for managing my Terraform configurations. Its intuitive design and comprehensive features have significantly improved my infrastructure deployment process. Highly recommend it for anyone looking to streamline their Terraform tasks! Check it out on GitHub: https://github.com/guilhermeyoshida/mcp-terraform-assistant.