It’s great to see that Microsoft listens to the pain that developers and devops professionals go through in working with Azure. Specifically that ARM templates, whilst very powerful, are insanely verbose and cumbersome to work with. Hence Project Bicep which is at it’s core a DSL for generating ARM templates. In this post I’m not going to go into much details on how to work with .bicep files but rather on how you can use a .bicep file in your Azure DevOps pipeline to deploy resources to Azure.
If you are interested in learning more about Project Bicep and the .bicep file format, here are some posts that provide some introductory material:
- Project Bicep, an ARM Domain-Specific Language
- Project Bicep – beyond ARM templates
- GitHub Action for Project Bicep (ARM DSL)
In order to deploy a .bicep file to Azure, you first need to use the bicep command line to generate the corresponding ARM template. You can then deploy the ARM template to Azure. Rather than having to add multiple steps to your build pipeline, wouldn’t it be nice to have a single step that you can use that simply takes a .bicep file, some parameters and deploys it to Azure. Enter the bicep-run template that is part of the 0.7.0 release of Pipeline Templates.
If you haven’t worked with any of the templates from the Pipeline Templates project, here’s the quick getting started:
Add the following to the top of your pipeline – this defines an external repository called
all_templates that can be referenced in your pipeline.
resources: repositories: - repository: all_templates type: github name: builttoroam/pipeline_templates ref: refs/tags/v0.7.0 endpoint: github_connection
Next, we’re going to use the bicep-run template to deploy our .bicep file to Azure.
- template: ../../steps/bicep/bicep-run.yml parameters: name: BicepRun az_service_connection: $(service_connection) az_resource_group_name: $(resource_group_name) az_resource_location: $(resource_location) bicep_file_path: '$(bicep_filepath)' arm_parameters: '-parameter1name $(parameter1value) -parameter2name $(parameter2value)'
The bicep-run wraps the following:
- Downloads and caches the Project Bicep command line. It currently references the v0.1.37 release but you can override this by specifying the bicep_download_url – make sure you provide the url to the windows executable, not the setup file.
- Runs the Bicep command line to covert the specified .bicep file (bicep_file_path parameter) into the corresponding ARM template
- Uses the Azure Resource Group Deployment Task to deploy the ARM template into Azure. The arm_parameters are forwarded to the overrideParameters parameter on the Azure Resource Group Deployment task.
Would love feedback on anyone that takes this template for a spin – what features would you like to see added? what limitations do you currently see for Project Bicep and the ability to run using this task?
Note: The bicep-run template is designed to run on a windows image.