Introduction
Hashicorp recently released a first version of an MCP server for Terraform that was announced at Microsoft Build. This allows us to enrich the experience with GitHub Copilot Chat when it comes to Terraform.
Currently the focus is on querying the Terraform Registry for artifact information and request recommendations.
In this blog post I want to guide you through the setup which has some pitfalls and show you some first experiences with the MCP server.
The Setup
To start our journey with the Terraform MCP server we must have some prerequisites in place namely:
- Docker is installed and running
- VS Code is installed and GitHub Copilot is set up. Make sure that you are running the latest stable version. The last few versions of VS Code came with some improvements and bug fixes when it comes to GitHub Copilot Chat and the integration with MCP servers.
If these prerequisites are in place we will first download the Docker image of the MCP server from Docker Hub via the command line:
docker pull hashicorp/terraform-mcp-server:latest
Now let's switch to VS Code and set up the configuration needed for the MCP server. I struggled a bit with the setup, and I got the impression that the documentation is a bit unclear, but maybe it is only me. Let's go through the steps together.
First, we must make sure that the settings in VS Code are matching the requirements for the MCP setup. There are two things that you need to check:
- In the settings of VS Code make sure that the Agent mode for GitHub Copilot Chat is enabled:
Next, we must make sure that the MCP server is enabled:
Next, we want to make GH Copilot aware that there is a MCP server available. There are different options available:
- Workspace setting - configuration for the current workspace
- User settings - configuration for all workspaces
- Autmatic discovery - this enables a auto discovery of an MCP server exposed by tools like Claude Desktop.
We will do the setup for one VS Code workspace (and do not mix it up with Terraform workspaces).
To do so, we create a new folder called test-terraform-mcp
. Inside of this folder we create another folder called .vscode
Inside of the .vscode
folder we create an empty file called mcp.json
. We open the empty JSON file in VS Code:
There is a blue button in the lower right corner that says, "Add Server ...". Do not use this button. This opens some guided procedure that didn't help me at all and also behaves different than documented. We will paste the required configuration directly into the file. The configuration looks like this:
{
"servers": {
"terraform": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"hashicorp/terraform-mcp-server"
]
}
}
}
Now we save the file and wait a bit. Now we see a tiny start
link in the line below "servers"
We press the start
link to start the MCP server as defined in the mcp.json
file. This will start the Docker container. This also changes the available links displayed in the mcp.json
file:
Let's do another check that GitHub Copilot is aware of the MCP server. We open GitHub Copilot Chat and make sure that we are in the Agent mode:
Now we click on the tool icon in the Copilot Chat and check if the MCP server is available:
This opens a list in the command palette of VS Code showing all available MCP servers and their toolsets. The result should look like this:
Okay we are ready to go. The MCP server is running, and GitHub Copilot Chat is aware of it. Now we can start asking questions.
The Test Drive
Time to challenge the MCP server with some questions. My home turf is the Terraform provider for SAP BTP. Let's see if the MCP server can help us with some questions around the provider.
Let's start with a question about entitlements and what resources are available in the provider:
What I learned quickly is that you must point the MCP server to the right namespace and provider name. Names like "Terraform provider for SAP BTP" do not work well. GitHub Copilot might be able to finally find the provider, but some steps are needed in the agentic execution to get on the right track.
The agent will execute serveral steps using the MCP server toolsets to get to the result. Everything is transparent for the user which is nice:
And the result looks good:
That's what we expected. Let's go a bit deeper and ask for the details of the entitlements on subaccount level:
Yes that seems to work fine. Let's switch gears and test the other toolsets about modules:
The result is this:
Hmmm ... that's not exactly what we expected. Let's cross check the Terraform Registry to see if there are more modules available:
Okay let's give Copilot another chance and ask if there aren't any other modules available:
It stays confident with the (incomplete) answer. Then let's ask directly for the missing module:
Okay, now it found the module. I have no idea why it missed it as the metadata in the registry seems to connect the dots correctly, but maybe the search query from the toolset is restricting the results to "something with BTP" which is not visible in the module itself. Interesting to see that the metadata doesn't seem to be a part of query.
Conclusion
The MCP server for Terraform adds some nice features to the GitHub Copilot Chat experience. I see some value when starting with Terraform on SAP BTP and have such a integrated experience. Having said that for experienced users I see only limited value (despite of trying it like I did). To be fair, the MCP server for terraform is still in a very early stage (it's beta and version 0.1.0) so I am curious to see how it will evolve in the future. I will keep an eye on it.
When it comes to the setup. I think this could be a bit smoother with more details in the documentation, but overall it is not too complicated, and things are moving fast when it comes to VS Code and GitHub Copilot. I am quite sure that the setup will be easier in the future.
References
Here are some references for more information about the Terraform MCP server and MCP servers in VS Code:
Top comments (0)