This guide will help you set up and use the Terraform Model Context Protocol (MCP) server with GitHub Copilot.
Before you begin, ensure you have the following installed:
-
Windows Subsystem for Linux (WSL)
- Required for running Linux-based containers on Windows
- Official WSL Installation Guide
-
Docker Desktop
- Required for running the Terraform MCP server container
- Download Docker Desktop
-
Visual Studio Code
- With the following extensions installed:
- GitHub Copilot
- GitHub Copilot Chat
- Model Context Protocol (MCP)
- With the following extensions installed:
-
Pull the Terraform MCP Server Image
docker pull hashicorp/terraform-mcp-server
-
Enable GitHub Copilot and MCP
- Open VS Code Settings
- Verify GitHub Copilot is activated
- Enable MCP extension
-
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.
- Create a new file at
-
Start the MCP Server
-
Verify Docker Container
- Run the following command to check if the Terraform MCP container is running:
docker ps
-
Check Available Functions
When using GitHub Copilot with the Terraform MCP server:
-
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
-
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