Convert ARM Template to Bicep and Deploy with Azure DevOps - Part 2 - Migration

2022, Feb 09

This is the second part of the series where an ARM Template is converted to Bicep. In this article, we should continue on Phase 2 - Migration.

Phased Migration

As a reference to Part 1, Microsoft suggests a migration in 5 phases, to convert the ARM Template into Bicep Template.

Five-Phases

The comprehensive details provided by Microsoft Docs are available as a reference1

Phase 2 - Migration

On this migration, we should end up with a version that is very close to what we are going to have for Production. The bicep file azuredeploy.bicep generated will help us to create a draft version.

It is worth mentioning that we are going to modify the bicep file to more closely match of what we need in Production, and it means that we should identify and fill any missing references that did not come from the ARM Template. Will we need to do that? It depends on the resource. In some cases, the information from the ARM Template isn't a supported resource type for export, and that requires us to tweak the bicep template to get the configuration we need.

The new draft Bicep template looks like this:

@minLength(1)
@maxLength(3)
param environment string

@minLength(3)
param appPlanName string

@description('Describes plan\'s pricing tier and capacity. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/')
@allowed([
  'F1'
  'D1'
  'B1'
  'B2'
  'B3'
  'S1'
  'S2'
  'S3'
  'P1'
  'P2'
  'P3'
  'P4'
])
param appPlanSKU string = 'F1'

param location string = resourceGroup().location

var webSiteName = 'sample-web-${environment}'

resource appPlan 'Microsoft.Web/serverfarms@2021-02-01' = {
  name: appPlanName
  location: location
  sku: {
    name: appPlanSKU
  }
  kind: 'app'
  tags: {
    displayName: 'HostingPlan'
  }
}

resource appWeb 'Microsoft.Web/sites@2020-12-01' = {
  name: webSiteName
  location: location
  kind: 'app'
  properties:{
    serverFarmId: appPlan.id
  }
  tags: {
    displayName: 'Website'
  }
}

resource aiWeb 'Microsoft.Insights/components@2020-02-02' = {
  name: webSiteName
  location: location
  kind: 'web'
  properties: {
    Application_Type: 'web'
  }
  tags: {
    displayName: 'AppInsightsComponent'
  }
  dependsOn: [
    appWeb
  ]
}

There were some changes if you compare them with the previous Bicep file. Can you spot the difference?

  • Variable names were modified to reflect a better label and meaning.
  • Component references were updated from @2015-08-01 to the latest available.
  • Some hidden tags were removed.

In Phase 3 we'll refactor this even more.

Full Series

Phase 1 - Convert

Phase 2 - Migration

Phase 3 - Refactor

Phase 4 - Test

Phase 5 - Deploy


  1. References: Migrate to Bicep