I have been using GitHub Copilot for a while now, and I love it! The AI assistant has significantly improved my coding efficiency and productivity. It suggests code snippets, assists with writing documentation (primarily descriptions and metadata), and even generates code based on my questions.
What is GitHub Copilot?
GitHub Copilot is a productivity tool that helps developers write code faster and more accurately. It offers auto-completion, code suggestions, and other helpful features. GitHub Copilot uses the OpenAI Codex to suggest code in real time. The OpenAI Codex is a generative pre-trained language model.
GitHub Copilot is trained on natural language text (just like ChatGPT) and public source code that is hosted on their platform. This vast dataset enables the AI assistant to suggest accurate and contextually relevant code snippets and solutions. The source code dataset contains around a billion lines of code.
GitHub Copilot is available in your editor. For Visual Studio Code you can use these extensions:
The service is not available for free. It comes with a two-month trial and costs $10 (~9.50 euro) a month after the trial.
GitHub Copilot collects data about your usage to help improve its features and services. If you’d prefer not to have your usage data collected, you can turn off telemetry as follows:
- Go to the Settings page of your GitHub account.
- On the Settings page go to the Copilot menu, and click the checkmark “Allow GitHub to use my code snippets for product improvements” to turn it off.
- Click the Save button.
Once you’ve turned off telemetry, your usage data will no longer be collected by GitHub Copilot for product improvements.
GitHub Copilot and Azure Bicep use cases
Here are three use cases for how I use GitHub Copilot:
1. Q&A with GitHub Copilot
In this use case, I ask GitHub Copilot to generate a code snippet based on a question. For this demonstration, I want to create a network security group to open the 3389 RDP port for my Windows VM in Azure. To achieve this, just simply ask GitHub Copilot the following question:
// Write a Network Security Group bicep that allows RDP access from the Internet
GitHub Copilot will generate the following response:
Github Copilot is a contextual AI. This means that it understands the context of the code being written. GitHub Copilot uses the context to determine what the next follow-up question might need to be in order to complete the Bicep file.
2. GitHub Copilot for inline Bicep documentation
In this use case, I will use GitHub Copilot to help me write inline documentation for parameters, variables or for creating metadata. To me, this is of real added value, since it helps me to keep focus on my technical work instead of thinking about documentation.
I have prepared an Azure Key Vault bicep with some parameters. For the demonstration, I want to decorate these parameters with the
@description decorator for extra context. In addition, I want to have some
@metadata for the access policies, to show what the access policies array expects:
3. Autocompletions based on GitHub Copilot suggestions
This is my most frequent use of GitHub Copilot. Here are some examples of autocomplete suggestions:
Defining a network interface card, which also has a reference to the subnet:
Adding a security rule for port 3389 as an inbound rule for a network security group:
For loop for creating multiple storage accounts based on the
Pros and Cons
Having used GitHub Copilot for Bicep, I’ve identified some pros and cons:
|Using GitHub Copilot can save you time by helping with tasks such as documenting and autocompleting code||Errors in the generated Bicep code. For example, inaccurate resource properties or generates JSON.|
|Keeps you in a development workflow||Sometimes the generation of limits to ~7 to 10 lines of code. See the screenshot below.|
|Direct IDE integration||It appears that the dataset available for Azure Bicep is smaller compared to other programming languages. Code suggestions for newer Bicep functions (lambda’s for example) are limited.|
GitHub Copilot is a promising tool for developers who are looking to improve their productivity. Its AI-assisted features like autocompletion, suggestion of code snippets, and writing documentation can save developers a lot of time, especially when it comes to writing complex code. GitHub Copilot can be a great productivity partner, but it’s good to keep in mind that it is not flawless, and its generated code should always be reviewed and validated before it’s used in production.
In conclusion, GitHub Copilot is a powerful tool that can help developers be more productive in their coding.
2 thoughts on “Three use cases for using GitHub Copilot with Azure Bicep”
Nice write up! I’ve been using the free month s while back. Bit kind of forgot about it. Bit perhaps I should give it a shot again! However, since copolit uses the contextual API, is it actually safe (security side) to use within a project that contains closed source corporate code?
Hi Seth, thanks!
For individual users (GitHub Copilot for Individuals) you have to choose whether to discard “code snippet data” via the setting “Allow GitHub to use my code snippets for product improvements” on your GitHub profile (https://github.com/settings/copilot).
For business users (GitHub Copilot for Business) on the other hand the “code snippet data” is discarded automatically and won’t be retained.
Source: https://github.com/features/copilot/ -> FAQ -> “Privacy – Copilot for Individuals” and “Privacy – Copilot for Business”.