Terraform MCP Server 介绍

Terraform MCP Server 旨在与 Terraform 生态系统无缝集成,从而为基础设施即代码 (IaC) 的开发提供高级自动化和交互能力。

License

MPL-2.0 license

35 stars 1 fork Branches Tags Activity

hashicorp/terraform-mcp-server

main

BranchesTags

目录和文件

| 文件夹/文件名 | | 最后提交信息 | 最后提交日期 | | :----------------------------------------------------------------------------------------------------------- | :- | :-------------------- | :----------------- | | .github | | | | | .release | | | | | cmd/terraform-mcp-server | | | | | e2e | | | | | pkg/hashicorp/tfregistry | | | | | scripts | | | | | version | | | | | .copywrite.hcl | | | | | .gitignore | | | | | .go-version | | | | | CODEOWNERS | | | | | Dockerfile | | | | | LICENSE | | | | | Makefile | | | | | README.md | | | | | go.mod | | | | | go.sum | | | |

查看所有文件

最新提交

历史

142 Commits

仓库文件导航

Terraform MCP Server

The Terraform MCP Server 是一个 Model Context Protocol (MCP) 服务器,它提供与 Terraform Registry API 的无缝集成,从而为基础设施即代码(IaC)开发实现高级自动化和交互功能。

使用场景

注意: MCP 服务器提供的输出和建议是动态生成的,并且可能因查询、模型和连接的 MCP 服务器而异。 用户在实施之前应彻底审查所有输出/建议,以确保它们符合其组织的安全最佳实践成本效益目标合规性要求

前提条件

  1. 要在容器中运行服务器,您需要安装 Docker
  2. 安装 Docker 后,您需要确保 Docker 正在运行。

安装

在 VS Code 中使用

将以下 JSON 代码块添加到 VS Code 的用户设置 (JSON) 文件中。 您可以通过按“Ctrl + Shift + P”并键入“Preferences: Open User Settings (JSON)”来完成此操作。

有关在 VS Code 的 agent mode documentation 中使用 MCP 服务器工具的更多信息。

{
  "mcp": {
    "servers": {
      "terraform": {
        "command": "docker",
        "args": [
          "run",
          "-i",
          "--rm",
          "hashicorp/terraform-mcp-server"
        ]
      }
    }
  }
}

或者,您可以将类似示例(即,没有 mcp 键)添加到工作区中名为 .vscode/mcp.json 的文件中。 这将允许您与他人共享配置。

{
  "servers": {
    "terraform": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "hashicorp/terraform-mcp-server"
      ]
    }
  }
}

关于在 Claude Desktop 中使用 MCP server tools 的更多信息,请参考 user documentation

在 Claude Desktop 中使用

{
 "mcpServers": {
  "terraform": {
   "command": "docker",
   "args": [
    "run",
    "-i",
    "--rm",
    "hashicorp/terraform-mcp-server"
   ]
  }
 }
}

工具配置

可用的工具集

以下工具集可用:

| 工具集 | 工具 | 描述 | | :------------ | :-------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | providers | resolveProviderDocID | 查询 Terraform Registry 以使用指定的 serviceSlug 查找并列出特定 provider 的可用文档。 返回 provider 文档 ID 列表,其中包含资源、数据源、函数或指南的标题和类别。 | | providers | getProviderDocs | 使用从 resolveProviderDocID 工具获得的文档 ID,获取特定 provider 资源、数据源或函数的完整文档内容。 以 markdown 格式返回原始文档。 | | modules | searchModules | 根据指定的 moduleQuery 搜索 Terraform Registry 中的模块(带分页)。 返回模块 ID 列表,其中包含其名称、描述、下载计数、验证状态和发布日期 | | modules | moduleDetails | 使用从 searchModules 工具获得的模块 ID 检索模块的详细文档,包括输入、输出、配置、子模块和示例。 |

从源码构建

如果您没有 Docker,可以使用 make build 直接从源代码构建二进制文件。 您应该将服务器配置为使用构建的可执行文件作为其 command

  1. 克隆存储库:
git clone https://github.com/hashicorp/terraform-mcp-server.git
cd terraform-mcp-server
  1. 构建二进制文件:
make build
{
 "mcp": {
  "servers": {
   "terraform": {
    "command": "/path/to/terraform-mcp-server",
    "args": ["stdio"]
   }
  }
 }
}

在本地构建 Docker 镜像

在使用服务器之前,您需要在本地构建 Docker 镜像:

  1. 克隆存储库:
git clone https://github.com/hashicorp/terraform-mcp-server.git
cd terraform-mcp-server
  1. 构建 Docker 镜像:
make docker-build

这将创建一个本地 Docker 镜像,您可以在以下配置中使用它。

{
 "servers": {
  "terraform": {
   "command": "docker",
   "args": [
    "run",
    "-i",
    "--rm",
    "terraform-mcp-server"
   ]
  }
 }
}

开发

前提条件

运行测试

# 运行所有测试
make test
# 运行 e2e 测试
make test-e2e

可用的 Make 命令

make build    # 构建二进制文件
make test     # 运行所有测试
make test-e2e   # 运行端到端测试
make clean    # 移除构建产物
make deps     # 下载依赖
make docker-build # 构建 docker 镜像

贡献

  1. Fork 存储库
  2. 创建您的 feature 分支
  3. 进行更改
  4. 运行测试
  5. 提交 pull request

License

该项目根据 MPL-2.0 开源许可的条款获得许可。 有关完整条款,请参阅 LICENSE 文件。

安全

对于安全问题,请联系 security@hashicorp.com 或遵循我们的 security policy

支持

对于错误报告和功能请求,请在 GitHub 上打开一个 issue。 对于一般性问题和讨论,请打开一个 GitHub Discussion。

关于

The Terraform MCP Server 旨在与 Terraform 生态系统无缝集成,从而为基础设施即代码 (IaC) 的开发提供高级自动化和交互能力。

资源

Readme

License

MPL-2.0 license

Code of conduct

Code of conduct

Security policy

Security policy

Activity Custom properties

Stars

35 stars

Watchers

3 watching

Forks

1 fork

Report repository

Releases 1

v0.1.0 Latest May 19, 2025

Contributors 4

编程语言