HomeAbout Me

What is Azure Bicep | How to deploy Azure Bicep with Azure DevOps pipeline

By Sri Gunnala
Published in Microsoft Azure
December 02, 2022
1 min read
What is Azure Bicep | How to deploy Azure Bicep with Azure DevOps pipeline

What is Azure Bicep Language
What is Azure Bicep Language

What is Bicep - Bicep is a transpiler that converts new Bicep Language to ARM templates. We will look into Bicep language in a second. Before that, let’s take a step back and understand why this was introduced.



Why Bicep?

If you have been working with JSON ARM templates, you would have noticed how cumbersome it can be when it is large. There are problems with current JSON ARM templates

  1. The current ARM template is not human-readable and it is hard to learn.
  2. It is in JSON structure. Json at the fundamental level designed for machine communication
  3. It is not intended for humans to read or write.
  4. As the file grows large, it adds extra noise with multiple levels of brackets.

Microsoft wants to simplify this and ensure only one path to deploy on Azure. But, Azure Resource Manager is huge and it has APIs for every service in Azure that works with Json ARM template. Its a huge work to change this. So, instead of making changes to Azure Resource Manager, Microsoft has introduced a new language called Bicep and built a transpiler that converts bicep language to ARM templates.

The bicep is a transpiler. A transpiler that converts the new Bicep language into ARM Templates.

Bicep local setup

Follow the instructions below.

https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/install

Sample Bicep Code

var storageAccountName = 'strgaazfunction'
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-05-01' = {
  name: storageAccountName
  location: location
  sku: {
    name:'Standard_LRS'
  }
  kind: 'Storage'
}

It is

  1. Very concise and more compact
  2. Very easy to read
  3. It supports modularity and code reusability.
  4. Most importantly, It has greater intellisense - You want to identify all possible errors before you compile. This is very crucial for productivity.

Deploy Azure Bicep through the DevOps pipeline

We will deploy a simple Azure function bicep template using Azure devops pipeline.

Download the bicep template for azure functions here - git repo

For a detailed walk-through, refer to the YouTube video shared above

  1. Download the source code from the above git repo and add it to the Azure DevOps repo
  2. Create a new Service Connection. It is used to connect to the Azure environment and create/modify resources.
  3. Create a new pipeline for the git repo and paste the below YAML code.
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger: none

pool:
  vmImage: ubuntu-latest

stages:

  - stage: Lint
    jobs:
    - job: LintCode
      displayName: Lint Code
      steps:
        - script: |
            az bicep build --file function-consumption-plan/storage.bicep
          name: LintBicepCode
          displayName: Run Bicep Linter
          
  - stage: Validate
    jobs:
      - job: ValidateBicepCode
        displayName: Validate Bicep Code
        steps:
          - task: AzureCLI@2
            name: RunPreflightValidation
            displayName: Run Preflight Validation
            inputs:
              azureSubscription: 'Subscription-PAYG'
              scriptType: 'bash'
              scriptLocation: 'inlineScript'
              inlineScript: |
                az deployment group validate --resource-group $(resourceGroupName) \
                 -f function-consumption-plan/storage.bicep \
                 --parameters function-consumption-plan/storage.parameters.json

  - stage: Deploy
    jobs:
      - job: Deploy
        steps:
          - task: AzureCLI@2
            name: Deploy
            displayName: Deploy to Azure
            inputs:
              azureSubscription: 'Subscription-PAYG'
              scriptType: 'bash'
              scriptLocation: 'inlineScript'
              inlineScript: |
                az deployment group create --name $(Build.BuildNumber)  --resource-group $(resourceGroupName) \
                 -f function-consumption-plan/storage.bicep \
                 --parameters function-consumption-plan/storage.parameters.json

  1. Modify Service Connection and file path to match your DevOps.
  2. Run the pipeline to create the resources.

Tags

#Azure#Bicep
Previous Article
Azure Standard Logic App with Secured (Private) Storage Account
Sri Gunnala

Sri Gunnala

Learner | Reader | Blogger | Azure Enthusiast

Topics

Front End
Microsoft Azure
Microsoft .NET

Newsletter

Sri Gunnala - Make sure to subscribe to newsletter and be the first to know the news.

Related Posts

A Quick Introduction to Azure SQL Trigger for Functions | Example | Demo
January 04, 2024
1 min

Legal Stuff

Privacy NoticeCookie PolicyTerms Of Use

Social Media