GenAI-Driven Infrastructure Deployment: GitHub Copilot for Azure Bicep and Terraform

GenAI-Driven Infrastructure Deployment: GitHub Copilot for Azure Bicep and Terraform


Automating Resource Deployment using Azure Bicep:

Creating Infrastructure as Code (IaC) can often present its own set of challenges. Especially when we have to deploy multiple resources at a time. In real time projects we have multiple environments and each one of it will have individual parameters and customizations. Manually creating separate biceps files, parameters file for each resources involves a lot of time and complexity. That is where GitHub Copilot comes into the picture. It acts as your virtual colleague which can assist you in your programming needs.

?

Pre-requisites:

1.????? VS Code

2.????? Azure Terraform

3.????? Azure Biceps

4.????? GitHub Copilot license



Github Copilot Chat Prompt

In the above screenshot I have asked the copilot to create couple of resources.

From the visualization (below) we can check every resource is there without any error or warnings. We can deploy it directly from our VS code terminal to the Azure Portal.


VS Code Bicep Visualize Panel

Now, I have asked Copilot to create one README.md file for the above code and it has generated correctly.


README.md

Generating parameters file for a bicep file could be time consuming and a lot of manual work specially when your bicep file has more than hundreds of lines of code. Here with the help of copilot we can generate it within few seconds.

For example, In the below image you can see I have asked the copilot to generate a parameters file for one of my existing generic bicep file (in the workspace) and it is able create it correctly.


Parameters file in .json format

In the above image, copilot has generated the parameters file for bicep in .json format. Let’s see whether it can generate it in .bicepparam format.


parameters file in .bicepparam format

As you can see it is able to generate the parameters file in a different format as well. Now you can change the names, location etc. as per your requirements.

?

GitHub Copilot Autocomplete Feature:

I have been utilizing GitHub Copilot's autocomplete feature for a variety of scenarios.

For instance, when you name your resource AppService Copilot will suggest autocompletions relevant to "AppService." Addition to that, if you have written the code for Appservice plan then copilot will auto suggest you and give you the code to deploy an Appservice.

In the below two images I have used the vs code editor to give instructions to write bicep code for app service plan and then the copilot has auto suggested me to create an Appservice, based on the Appservice plan.


Press ctrl+I to ask GitHub to do something

?

Auto suggestions based on previously written code

?

Terraform Module Generation with GitHub Copilot:

As of now we have given pretty much straight forward tasks/prompts to copilot. Now Let’s discuss some complex scenarios where we can leverage the efficiency of Copilot.

Often organizations demand the separation for each of the resources in their infra. So here we have to modularize the terraform configuration. In the below screen shot I have given a prompt for creating couple of resources and modularize it.

As you can see it has given me the modules for each of the resources, it has created a separate main.tf and variable.tf file.


Terraform module generation for each mentioned resources

?

?

?

Separate main and variables file


Separate main and variables file

Now lets’ give copilot a more complex scenario and check if it’s able to perform. I have asked the copilot to rewrite the script considering I am using separate repo for each of these modules.


Each module for separate repo

?

Each module for separate repo

?

As shown in the examples above, it may not be always accurate all the time but it typically covers 70-80% of what you need. You can then leverage your knowledge to complete the remaining parts, customize as per your project requirement which saves considerable time and enhances your productivity and code quality.

?



要查看或添加评论,请登录

Rituparna Bandyopadhyay的更多文章

社区洞察

其他会员也浏览了