Terraform MCP Server

Terraform MCP Server

DevOps
HashiCorp
claudecursorvscodecodexgeneric
FreeOpen Source

À propos de ce serveur

Le serveur officiel Terraform MCP par HashiCorp. Permet aux agents IA de s'intégrer de manière transparente avec l'écosystème Terraform : gérer les fichiers d'état, planifier l'exécution et écrire de l'infrastructure en tant que code (IaC).

Installation

npx -y @hashicorp/terraform-mcp-server
Guide d'installation officiel du README (en anglais)

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>

Questions fréquentes

Que peut faire Terraform MCP ?

Permet aux agents IA d'écrire et d'exécuter directement des configurations Terraform : gérer les fichiers d'état, visualiser et créer des plans d'exécution, prévisualiser les changements de ressources, et lire les configurations et sorties Terraform. Rendant la gestion d'infrastructure plus intelligente et efficace.

Terraform MCP nécessite-t-il l'installation de Terraform ?

Oui, vous devez avoir Terraform CLI installé localement. Le serveur MCP exécute les opérations en appelant la commande terraform locale, vous aurez donc besoin de Terraform installé et des identifiants du fournisseur cloud configurés.

Terraform MCP est-il gratuit ?

Entièrement gratuit et open source (licence BUSL), officiellement maintenu par HashiCorp. Le serveur MCP lui-même est gratuit, mais la gestion des ressources cloud avec Terraform entraînera des frais de votre fournisseur cloud en fonction de l'utilisation des ressources.