Blog Post

Azure Infrastructure Blog
3 MIN READ

Unleashing GitHub Copilot for Infrastructure as Code

umurugesan's avatar
umurugesan
Icon for Microsoft rankMicrosoft
Apr 26, 2024
 

Introduction

In the world of managing infrastructure, things are always changing. People really want solutions that work, can handle big tasks, and won't let them down. Now, as more companies switch to using cloud-based systems and start using Infrastructure as Code (IaC), the job of folks who handle infrastructure is getting even more important. They're facing new problems in setting up and keeping everything running smoothly.

 

The Challenges faced by Infrastructure Professionals

  1. Complexity of IaC: Managing infrastructure through code introduces a layer of complexity. Infrastructure professionals often grapple with the intricate syntax and structure required by tools like Terraform and PowerShell. This complexity can lead to errors, delays, and increased cognitive load.
  2. Consistency Across Environments: Achieving consistency across multiple environments—development, testing, and production—poses a significant challenge. Maintaining uniformity in configurations is crucial for ensuring the reliability and stability of the deployed infrastructure.
  3. Learning Curve: The learning curve associated with IaC tools and languages can be steep for those new to the domain. As teams grow and diversify, onboarding members with varying levels of expertise becomes a hurdle.
  4. Time-Consuming Development Cycles: Crafting infrastructure code manually is a time-consuming process. Infrastructure professionals often find themselves reinventing the wheel, writing boilerplate code, and handling repetitive tasks that could be automated.

 

Unleashing GitHub Copilot for Infrastructure as Code

In response to these challenges, Leveraging GitHub Copilot to generate infra code specifically for infrastructure professionals is helping to revolutionize the way infrastructure is written, addressing the pain points experienced by professionals in the field.

The Significance of GH Copilot for Infra

  1. Code Generation with accuracy: Copilot harnesses the power of machine learning to interpret the intent behind prompts and swiftly generate precise infrastructure code. It understands the context of infrastructure tasks, allowing professionals to express their requirements in natural language and receive corresponding code suggestions.
  2. Streamlining the IaC Development Process: By automating the generation of infrastructure code, Copilot significantly streamlines the IaC development process. Infrastructure professionals can now focus on higher-level design decisions and business logic rather than wrestling with syntax intricacies.
  3. Consistency Across Environments and Projects: GH Copilot ensures consistency across environments by generating standardized code snippets. Whether deploying resources in a development, testing, or production environment, GH Copilot helps maintain uniformity in configurations.
  4. Accelerating Onboarding and Learning: For new team members and those less familiar with IaC, GH Copilot serves as an invaluable learning service. It provides real-time examples and best practices, fostering a collaborative environment where knowledge is shared seamlessly.
  5. Efficiency and Time Savings: The efficiency gains brought about by GH Copilot are substantial. Infrastructure professionals can witness a dramatic reduction in development cycles, allowing for faster iteration and deployment of infrastructure changes.

Copilot in Action

Prerequisites

      1.Install visual studio code latest version - https://code.visualstudio.com/download

  1. Have a GitHub Copilot license with a personal free trial or your company/enterprise GitHub account, install the Copilot extension, and sign in from Visual Studio Code. https://docs.github.com/en/copilot/quickstart
  2. Install the PowerShell extension for VS Code, as we are going to use PowerShell for our IaC sample.

Below is the PowerShell code generated using VS Code & GitHub Copilot. It demonstrates how to create a simple Azure VM.

We're employing a straightforward prompt with #, with the underlying code automatically generated within the VS Code editor.

 

Another example to create azure vm with vm scale set with minimum and maximum number of instance count. Prompt used with # in below example.

 

The PowerShell script generated above can be executed either from the local system or from the Azure Portal Cloud Shell. Similarly, we can create Terraform and devops code using this Infra Copilot.

 

Conclusion

In summary, GH Copilot is a big deal in the world of infrastructure as code. It helps professionals overcome challenges and brings about a more efficient and collaborative way of working. As we finish talking about GH Copilot's abilities, the examples we've looked at have shown how it works, what technologies it uses, and how it can be used in real life. This guide aims to give infrastructure professionals the info they need to improve how they do infrastructure as code.

 

Updated Apr 30, 2024
Version 10.0
  • Ryan Yates's avatar
    Ryan Yates
    Brass Contributor

    FYI this really isn't anything new and calling the functionality exposed by GitHub Copilot as InfraCopilot isn't really helpful tbh.

     

    This post could be the same post just totally removing all InfraCopilot references and saying using Copilot for IaC.

     

    That said we really don't need to confuse things by redefining GitHub Copliot as InfraCopilot or JavaScriptCopilot or dotnetCopilot etc etc etc unless they are built not just using GitHub Copilot as the underlying tool but one that works across not only GitHub but internet searches and other data stores like GitLab or Bitbucket or blogposts or internal applications like knowledgebases etc

     

    But other than that this is a good post, and I hope gets more interested in using this good bit of tooling in future

  • mmlime's avatar
    mmlime
    Copper Contributor

    Hi, great, but what about Bicep? Nobody use PowerShell for IaC, or ??

  • Hi mmlime  - Thanks for reaching out. Yes, GH copilot does support for Bicep. 

    Absolutely, you make a good point about Bicep! Bicep is gaining popularity for managing resources in Azure because it's simpler and more focused than PowerShell. It’s really useful for straightforward deployments in Azure.

    However, PowerShell is still very much in use because it's versatile. It works across different environments, not just Azure, and is great for more complex tasks that need detailed scripting. Each tool has its strengths, so it really comes down to what you need for your specific project.

  • Hi MariDelgado  - Thank you for your interest in our article. Terraform also provides support for this, as mentioned in the article.

  • Hi Ryan Yates  - Thank you for getting in touch. I want to clarify that in the article, I explicitly state that Infra Copilot is a term that utilizes GH Copilot and clearly, it's not new product or tool. It's important to note that the app domain differs from the infra domain, and often, there's a misconception that GH Copilot is solely for app code like .NET, Java, Python, etc. Hence, the purpose of the article is to shed light on the term "Infra Copilot" by leveraging GH Copilot. Moreover, we adhere to a standard process for any product release, which typically wouldn't be announced through an article. The article has now been updated only with GH Copilot to address any potential confusion. Thanks.

  • Absolutely! Consider the vast pool of Infrastructure Subject Matter Experts (SMEs) who excel in their field but may not have a coding background. Many of them rely on graphical user interfaces (GUIs) for their day-to-day operations. Traditionally, organizations faced a dilemma: either hire new DevOps personnel at a considerable cost or struggle to integrate automation into their workflows.

    Enter GitHub Copilot, a game-changer in the realm of coding assistance. With Copilot, organizations now have an unprecedented opportunity to bridge this gap seamlessly. By empowering existing resources with Copilot, they can unlock a new era of automation and efficiency within their infrastructure teams.

    It's essential to recognize that while coding is a valuable skill, its essence lies not merely in syntax but in the logic and structure it embodies. GitHub Copilot embodies this philosophy by enabling users to express their intentions through pseudocode, which it then effortlessly translates into specific programming languages.

    In essence, GitHub Copilot democratizes coding, making it accessible to everyone, regardless of their coding background. It empowers Infrastructure SMEs to become proficient in automation without the need for extensive coding knowledge, thereby fostering innovation and productivity within organizations.

    Harness the power of GitHub Copilot to elevate your infrastructure operations, streamline processes, and unleash the full potential of your talented workforce. The future of automation is here, and it's within reach with GitHub Copilot.

     

  • Hi, great article on IaC, it would be better if you add IaC code for compute intensive systems and GPU based machines.