terraform-mcp-server-setup

Deedeo/terraform-mcp-server-setup

3.1

If you are the rightful owner of terraform-mcp-server-setup and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The Model Context Protocol (MCP) server is a tool designed to facilitate the integration and management of various model-based applications, enhancing productivity and collaboration.

Getting Started with Terraform MCP Server Using GitHub Copilot

This guide will help you set up and use the Terraform Model Context Protocol (MCP) server with GitHub Copilot.

Table of Contents

  1. Prerequisites
  2. Installation Steps
  3. Configuration
  4. Verification
  5. Usage

Prerequisites

Before you begin, ensure you have the following installed:

  1. Windows Subsystem for Linux (WSL)

  2. Docker Desktop

  3. Visual Studio Code

    • With the following extensions installed:
      • GitHub Copilot
      • GitHub Copilot Chat
      • Model Context Protocol (MCP)

Installation Steps

  1. Pull the Terraform MCP Server Image

    docker pull hashicorp/terraform-mcp-server
    

    Terraform MCP Server Image

  2. Enable GitHub Copilot and MCP

    • Open VS Code Settings
    • Verify GitHub Copilot is activated
    • Enable MCP extension

    GitHub Copilot Agent Enabled MCP Extension Enabled

Configuration

  1. Create MCP Configuration File

    • Create a new file at .vscode/mcp.json in your project root
    • Add the following configuration:
    {
      "servers": {
        "terraform": {
          "command": "docker",
          "args": [
            "run",
            "-i",
            "--rm",
            "hashicorp/terraform-mcp-server"
          ]
        }
      }
    }
    

    Note: This configuration activates MCP specifically for this project. For other use cases, refer to the official Terraform MCP documentation.

Verification

  1. Start the MCP Server

    • Look for the start icon in VS Code Start MCP Server
  2. Verify Docker Container

    • Run the following command to check if the Terraform MCP container is running:
    docker ps
    

    Confirm MCP  Server container is up

  3. Check Available Functions

    • Click the tools icon in the GitHub Copilot chat section Tools Icon
    • You should see the list of available Terraform MCP functions MCP Functions

Usage

When using GitHub Copilot with the Terraform MCP server:

  1. Writing Prompts

    • Be specific in your requirements
    • Include relevant details about providers and resources
    • Example prompt:
      Using azure terraform provider, create a terraform template to provision a windows vm on azure
      

    Example Prompt

  2. Best Practices

    • Always specify the provider you want to use
    • Include resource requirements clearly
    • Review and validate generated configurations
    • Test in a non-production environment first

Additional Resources