Get the FREE Ultimate OpenClaw Setup Guide →

Terraform

This project provides an MCP (Model Context Protocol) server that exposes Terraform infrastructure-as-code operations through natural language. It enables LLMs to execute Terraform commands and retrieve information about infrastructure without requiring specific command syntax knowledge.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio jashkahar-terraform-mcp-server python src/main.py \
  --env LOG_LEVEL="INFO" \
  --env TERRAFORM_WORKSPACE="/path/to/terraform/workspace"

How to use

This MCP server provides a natural-language interface over Terraform operations. It translates everyday, human-friendly prompts into Terraform actions such as creating plans, inspecting state, applying configurations, and listing resources. Useful capabilities include natural-language processing of Terraform commands, visualization of execution plans, running state inspections, and managing deployments through the MCP’s tooling, all without requiring you to memorize Terraform syntax. Typical interactions might involve asking to generate a plan for the current workspace, show the resources in state, apply a configuration, or destroy infrastructure with descriptive prompts. The server is designed to interpret intent from user questions and map them to Terraform workflows, offering an abstraction layer that emphasizes clarity and safe operations.

To use, start the MCP server and send requests to its endpoints with your natural-language prompts. For example, you can request: initialize the Terraform workspace, show what would change with a plan, apply the configuration, list all resources, or destroy the infrastructure. The server will respond with structured results such as plan details, current state summaries, or execution outcomes, enabling you to manage infrastructure through conversational commands.

How to install

Prerequisites:

  • Python 3.8+ installed on your system
  • A Python virtual environment tool (optional but recommended)
  • Access to the Terraform configuration directory you want to manage

Step-by-step:

  1. Clone the repository:
git clone https://github.com/youruser/terraform-mcp-server.git
cd terraform-mcp-server
  1. Create and activate a virtual environment (optional but recommended):
python -m venv .venv
# Windows
.venv\Scripts\activate
# macOS/Linux
source .venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Configure environment variables (optional but recommended):
export TERRAFORM_WORKSPACE="/path/to/terraform/workspace"
export LOG_LEVEL="INFO"
  1. Start the MCP server:
python src/main.py
  1. Test the server locally by sending a request to the default port (as defined by the server). You can adjust the port or endpoints as needed in your configuration.

Prerequisites notes:

  • Ensure your Terraform configurations are accessible in the workspace defined by TERRAFORM_WORKSPACE.
  • If you plan to visualize plans, you may need Graphviz installed (see optional visualization in the notes below).

Additional notes

Tips and notes:

  • Environment variables: TERRAFORM_WORKSPACE should point to the directory containing your Terraform configs; LOG_LEVEL can be set to INFO, DEBUG, etc., for more verbose output.
  • Visualization: If you plan to generate visual representations of plans, consider installing Graphviz. On Windows, download from the Graphviz site; on macOS use brew install graphviz; on Linux use sudo apt-get install graphviz.
  • Dependency management: Keep requirements.txt in sync with your Python environment to avoid import errors.
  • Security: When exposing MCP endpoints, consider authentication/authorization and input validation to prevent unintended destructive actions.
  • Troubleshooting: If the server fails to start, check that the TERRAFORM_WORKSPACE path exists and contains valid Terraform configurations, and verify that you can run Terraform commands in that directory from a regular shell.

Related MCP Servers

Sponsor this space

Reach thousands of developers