Terraform MCP Server

Terraform MCP Server

DevOps
HashiCorp
claudecursorvscodecodexgeneric
FreeOpen Source

このサーバーについて

HashiCorp 公式の Terraform MCP サーバー。AI エージェントが Terraform エコシステムとシームレスに統合:状態ファイルの管理、プラン実行、Infrastructure as Code(IaC)の記述が可能です。

インストール

npx -y @hashicorp/terraform-mcp-server
公式 README インストールガイド(英語原文)

Usage with Visual Studio Code

Add the following JSON block to your User Settings (JSON) file in VS Code. You can do this by pressing Ctrl + Shift + P and typing Preferences: Open User Settings (JSON).

More about using MCP server tools in VS Code's agent mode documentation.

<table>

<tr><th>Version 0.3.0+ or greater</th><th>Version 0.2.3 or lower</th></tr>

<tr valign=top>

<td>

json
{
  "mcp": {
    "servers": {
      "terraform": {
        "command": "docker",
        "args": [
          "run",
          "-i",
          "--rm",
          "-e", "TFE_TOKEN=${input:tfe_token}",
          "-e", "TFE_ADDRESS=${input:tfe_address}",
          "hashicorp/terraform-mcp-server:1.1.0"
        ]
      }
    },
    "inputs": [
      {
        "type": "promptString",
        "id": "tfe_token",
        "description": "Terraform API Token",
        "password": true
      },
      {
        "type": "promptString",
        "id": "tfe_address",
        "description": "Terraform Address",
        "password": false
      }
    ]
  }
}

</td>

<td>

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

</td>

</tr>

</table>

Optionally, you can add a similar example (i.e. without the mcp key) to a file called .vscode/mcp.json in your workspace. This will allow you to share the configuration with others.

<table>

<tr><th>Version 0.3.0+ or greater</th><th>Version 0.2.3 or lower</th></tr>

<tr valign=top>

<td>

json
{
  "servers": {
    "terraform": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e", "TFE_TOKEN=${input:tfe_token}",
        "-e", "TFE_ADDRESS=${input:tfe_address}",
        "hashicorp/terraform-mcp-server:1.1.0"
      ]
    }
  },
  "inputs": [
    {
      "type": "promptString",
      "id": "tfe_token",
      "description": "Terraform API Token",
      "password": true
    },
    {
      "type": "promptString",
      "id": "tfe_address",
      "description": "Terraform Address",
      "password": false
    }
  ]
}

</td>

<td>

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

</td>

</tr>

</table>

<img alt="Install in VS Code (docker)" src="https://img.shields.io/badge/VS_Code-VS_Code?style=flat-square&label=Install%20Terraform%20MCP&color=0098FF">

<img alt="Install in VS Code Insiders (docker)" src="https://img.shields.io/badge/VS_Code_Insiders-VS_Code_Insiders?style=flat-square&label=Install%20Terraform%20MCP&color=24bfa5">

Usage with Cursor

Add this to your Cursor config (~/.cursor/mcp.json) or via Settings → Cursor Settings → MCP:

<table>

<tr><th>Version 0.3.0+ or greater</th><th>Version 0.2.3 or lower</th></tr>

<tr valign=top>

<td>

json
{
  "mcpServers": {
    "terraform": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e", "TFE_ADDRESS=<<PASTE_TFE_ADDRESS_HERE>>",
        "-e", "TFE_TOKEN=<<PASTE_TFE_TOKEN_HERE>>",
        "hashicorp/terraform-mcp-server:1.1.0"
      ]
    }
  }
}

</td>

<td>

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

</td>

</tr>

</table>

<a href="cursor://anysphere.cursor-deeplink/mcp/install?name=terraform&config=eyJjb21tYW5kIjoiZG9ja2VyIiwiYXJncyI6WyJydW4iLCItaSIsIi0tcm0iLCJoYXNoaWNvcnAvdGVycmFmb3JtLW1jcC1zZXJ2ZXIiXX0%3D">

<img alt="Add terraform MCP server to Cursor" src="https://cursor.com/deeplink/mcp-install-dark.png" height="32" />

</a>

Usage with Claude Desktop / Amazon Q Developer / Kiro CLI

More about using MCP server tools in Claude Desktop user documentation. Read more about using MCP server in Amazon Q Developer and Kiro CLI.

<table>

<tr><th>Version 0.3.0+ or greater</th><th>Version 0.2.3 or lower</th></tr>

<tr valign=top>

<td>

json
{
  "mcpServers": {
    "terraform": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e", "TFE_ADDRESS=<<PASTE_TFE_ADDRESS_HERE>>",
        "-e", "TFE_TOKEN=<<PASTE_TFE_TOKEN_HERE>>",
        "hashicorp/terraform-mcp-server:1.1.0"
      ]
    }
  }
}

</td>

<td>

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

</td>

</tr>

</table>

Usage with Claude Code

More about using and adding MCP server tools in Claude Code user documentation

  • Local (stdio) Transport
sh
claude mcp add terraform -s user -t stdio -- docker run -i --rm hashicorp/terraform-mcp-server
  • Remote (streamable-http) Transport
sh
# Run server (example)
docker run -p 8080:8080 --rm -e TRANSPORT_MODE=streamable-http -e TRANSPORT_HOST=0.0.0.0 hashicorp/terraform-mcp-server

# Add to Claude Code
claude mcp add --transport http terraform http://localhost:8080/mcp

Usage with Gemini extensions

For security, avoid hardcoding your credentials, create or update ~/.gemini/.env (where ~ is your home or project directory) for storing HCP Terraform or Terraform Enterprise credentials

text
# ~/.gemini/.env
TFE_ADDRESS=your_tfe_address_here
TFE_TOKEN=your_tfe_token_here

Install the extension & run Gemini

text
gemini extensions install https://github.com/hashicorp/terraform-mcp-server
gemini

Usage with Bob IDE / Shell

More about using and adding MCP servers tools in Bob IDE or Shell Using MCP in Bob.

<table>

<tr><th>Version 0.3.0+ or greater</th><th>Version 0.2.3 or lower</th></tr>

<tr valign=top>

<td>

json
{
  "mcpServers": {
    "terraform": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e", "TFE_ADDRESS=<<PASTE_TFE_ADDRESS_HERE>>",
        "-e", "TFE_TOKEN=<<PASTE_TFE_TOKEN_HERE>>",
        "hashicorp/terraform-mcp-server:1.1.0"
      ],
      "disabled": false
    }
  }
}

</td>

<td>

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

</td>

</tr>

</table>

よくある質問

Terraform MCP は何ができますか?

AI エージェントが Terraform 設定を直接記述・実行できます:状態ファイルの管理、実行計画の表示と作成、リソース変更のプレビュー、Terraform 設定と出力の読み取り。インフラ管理をよりスマートかつ効率的にします。

Terraform MCP を使用するには Terraform のインストールが必要ですか?

はい、ローカルに Terraform CLI のインストールが必要です。MCP サーバーはローカルの terraform コマンドを呼び出して操作を実行するため、Terraform のインストールとクラウドプロバイダーの認証情報の設定が必要です。

Terraform MCP は無料ですか?

完全無料・オープンソース(BUSL ライセンス)で、HashiCorp が公式メンテナンスしています。MCP サーバー自体は無料ですが、Terraform でクラウドリソースを管理する際、クラウドプロバイダーからリソース使用量に応じた料金が発生します。