Manage your public cloud with github Copilot, Terraform and Azure MCP - part 1

Reduce model hallucinations by providing Azure and Terraform MCPs to Copilot

AI

Jack Jalali

7/2/20255 min read

The Rise of AI Automation: Do We Still Need AI specialists?

As IT departments continue to navigate the complexities of public cloud infrastructure, a question lingers: do we really need IT experts or gurus to manage our cloud environments? In this series of posts, I'll argue that perhaps the answer is no, especially for smaller-sized IT teams.

These days automation tools have become increasingly sophisticated, enabling us to streamline processes and reduce manual labour. One such tool is GitHub Copilot, an AI-powered coding assistant that can help with a wide range of tasks, including infrastructure deployment.

A Test Case: A non-expert Using AI agent to Deploying a Virtual Machine to Azure

The main idea is instead of spending hours learning a new tool like terraform, use an AI agent and a LLM and give it loads of information, context, API documentations etc. about the tool and ask it to perform tasks like an expert.

To put this idea to the test, I'll be using GitHub Copilot to deploy a virtual machine to my Azure environment. But to ensure the best possible results and minimize errors, I'll provide Copilot with additional context by presenting it with Azure and Terraform MCP servers as tools. This will help the model better understand the context of these tools and hopefully reducing the likelihood of "model hallucinations" – instances where the AI generates code that doesn't quite fit the intended purpose.

By leveraging GitHub Copilot in this way, I aim to demonstrate that even complex infrastructure tasks can be accomplished without requiring specialised Terraform expertise. In future posts, we'll explore more scenarios and examine the implications of automation on IT departments of all sizes. Stay tuned to see how this experiment unfolds!

Prerequisites

  • Github Copilot

  • Azure subscription

  • vscode + extensions

The procedure

Start vscode and install, Github Copilot, Github Copilot chat and Github Copilot for Azure:

Review the following Azure-MCP and Terraform-MCP Githubs to learn more about Azure and Terraform's MCP servers.

Go to vscode's settings and add both MCP setups and make sure that they are running as shown below:

If you look at the agent's tools and search for mcp, you can see that the agent now has the capability to get terraform provider documentation and provider details as well as the ability to search for modules and their details. This additional knowledge or context can help to ensure better, faster and more accurate code generation.

Now let's connect to our Azure subscription, by now the extension for Azure should be installed and visible, click on the Azure icon and go to "Accounts & Tenants" and authenticate to your Azure environment:

You can test to see if Github can interact with Azure:

This should list all available resource groups. Now create an empty folder and call it something like, Terraform_MCP. Then use the agent to issue this command: "create a virtual machine using terraform". This will create the following file structure under the folder you created earlier:

Simplifying Deployment: Modifying Terraform Variables

To get started with deploying a virtual machine, all you need to do is modify the terraform.tfvars file with the details of the VM you want to deploy. As shown below, this straightforward process can be completed manually.

However, the true power of automation lies in its ability to streamline and simplify complex tasks. In the future, we can take this process to the next level by introducing a user-friendly interface (UI) that allows users to input their required specifications for Azure resources. With the click of a submit button, AI-powered automation can take over, completing the deployment task with ease.

For now, though, let's focus on the manual approach. By modifying the terraform.tfvars file, we'll lay the groundwork for a more automated process down the line. This will not only save time but also reduce the likelihood of human error, making it easier to deploy and manage resources in Azure.

A Glimpse into the Future of Automation

Imagine a scenario where users can simply fill out a form with their desired VM specifications, such as CPU, memory, and storage. With AI automation handling the deployment process, the need for manual intervention is minimized, and the risk of errors is significantly reduced. This is the future of infrastructure deployment, and it's an exciting prospect. But for now, let's take it one step at a time and focus on modifying those terraform variables!

At this stage I just ask the agent to "run an init and plan"

After that we ran into multiple issues and they were fixed one by one. Some were easy to fix, I had the required Azure region as "uks" instead of "UK south".

Eventually all issues were fixed:

and the VM was deployed successfully:

The summary of what was done Github Copilot:

  • terraform was installed using sudo snap install terraform --classic

  • the variable declaration issues were fixed in the configuration file

  • the os_disk configuration was fixed by adding the required storage_account_type parameter

  • logged in to Azure using az login

  • configured the provider to use the correct subscription ID

  • password authentication was enabled for the VM

  • finally, terraform apply was executed to create the resources

The following resources were successfully created in Azure:

  • Resource Group: AZ-IntTest_group

  • Virtual Network: example-network

  • Subnet: default

  • Network Interface: example-nic

  • Linux Virtual Machine: myVM

Taking Automation to the Next Level: Optimising Resource Management

As I reflect on the exercise I've just completed, I'm excited to explore ways to optimise the process and manage the entire lifecycle of resource creation and decommissioning. The potential for automation is vast, and I believe that GitHub Copilot can play a significant role in streamlining this process.

Creating a Web Application with GitHub Copilot

One possible next step is to use GitHub Copilot to create a web application that builds on the findings from my previous exercise. By leveraging the power of AI-powered coding, I can quickly develop a user-friendly interface that simplifies the process of managing resources in Azure. This could include features such as automated deployment, scaling, and decommissioning of resources, all with minimal manual intervention.

Exploring Workflow Automation with n8n

Another area I'm going to explore is automation using n8n. By creating a customised workflow that utilizes AI agents and MCP servers, I can automate complex tasks and reduce the risk of human error. n8n's flexible architecture and extensive library of nodes make it an ideal platform for building custom workflows that integrate with Azure and other cloud services.