πŸ’ͺ Azure Bicep CI/CD πŸš€

Hey, you. You’re not manually deploying your Azure Bicep Infrastructure as Code, are you?!? Let’s prevent that next production outage, help your team collaborate on changes, and enable more frequent deployments. In this post, I’ll outline what tooling is available to integrate Bicep in your pipelines, and some good practices for building and deploying.

Resources to get started

If you’re new to Azure Bicep, I’d recommend checking out the Microsoft Learn learning path for Bicep. There are also great resources for the basics on Deploying Bicep files by using GitHub Actions and Integrating Bicep with Azure Pipelines. Once you have the fundamentals covered, you may find the remainder of this post helpful.

Build

Tooling

I’m going to break things down into 2 phases of the pipeline: 1. build 2. deploy. For the build phase, we have multiple options for tooling:

Good Practices

I like to set up the build phase early in my pipeline, in order to fail fast and speed up the feedback loop. The build should make sure 3 things happen:

  • Ensure transpilation (conversion to ARM template) is successful.
  • Ensure linting rules pass. Configure bicepconfig.json to throw an error on important rule violations.
  • Ensure preflight validaton is successful.

To combine all of the above using a single command, validation commands can be used. For a resource group deployment, I can use the Azure CLI command az deployment group validate or Azure PowerShell’s Test-AzResourceGroupDeployment.

For an example of this using GitHub Actions, check out my SpaceGameVNext’s pipeline here.

Deploy

Tooling

Similar to build, we have multiple options for deployment:

Good Practices

I like to promote the same set of templates for all environments (dev -> test -> prod). This encourages the DRY (Don’t repeat yourself) principle. In order to make this happen, I can:

Additionally,

For an example of this using GitHub Actions, check out my SpaceGameVNext’s pipeline here.

Summary

None of this is hard and fast guidance to follow strictly. There are many different types of architectures, environments, repository structures, etc. These are things that I’ve found success with and YMMV. What have you found success in while integrating Bicep into your pipelines? I would love to hear your thoughts in the comments.

Leave a Reply

Your email address will not be published. Required fields are marked *