From ARM templates to Bicep

Moving from an ARM template to Bicep is usually your first step towards managing Azure as code. ARM templates are the JSON files Azure deploys, and Bicep is a shorter, cleaner language that compiles down to that same JSON, with type checking and error messages before anything gets deployed.

Most admins first come across ARM templates through the portal’s “Export template” button, and then find the JSON it gives them is long, full of hard-coded values and painful to reuse. Converting it to Bicep is the normal next move, though the converter has a few traps.

In the lab you’ll build an NSG by hand, export it and write a clean Bicep version, deploy that with a parameters file, and then fix the errors the decompiler and the compiler throw at you.

TimeYou needCostBy the end you can
About 45 minutesThe CLI with Bicep (Lesson 3), VS Code with the Bicep extensionNo cost: a network security group onlyRead ARM JSON, write and deploy Bicep with parameters, and fix decompile and parameter errors

What it is, in one line

Bicep is a simpler language for Azure Resource Manager templates that compiles into the same ARM JSON Azure deploys.

In Simple Words

The recipe card and the shopping list

An ARM template is a bit like a recipe written up as a long legal contract, with every ingredient spelled out in full and brackets and quotes all over the place. It works, but nobody enjoys reading it.

Bicep is that same recipe on a neat card: “2 eggs, 1 cup flour, bake 20 minutes”. When it’s needed, a helper turns the card back into the contract, so the kitchen (Azure) gets what it always got.

And when you copy a recipe from someone else’s kitchen (an export), you copy their oven settings and their spelling mistakes along with it, which is what you’ll be cleaning up today.

Engineer's View

ARM JSON vs Bicep

ARM template (JSON)Bicep
Fileazuredeploy.jsonmain.bicep
References[parameters(‘x’)], [resourceId(…)]x, nsg.id
DependenciesdependsOn written by handWorked out from references
ErrorsMostly at deploymentMost at build time, in VS Code
Parametersparameters.json.bicepparam with type checking
Deployed asJSONCompiled to JSON first
  • Same engine: Bicep doesn’t have a runtime of its own. az bicep build turns a .bicep file into ARM JSON, and it’s Resource Manager that deploys it.
  • Decorators: you use @description, @minValue, @maxValue, @allowed and @secure to document parameters and validate them.
  • Decompile: az bicep decompile converts ARM JSON to Bicep as best it can, so expect some warnings and errors you’ll need to fix by hand.
  • Exported templates repeat child resources such as NSG rules, once inside the parent and again as separate resources, and they hard-code names and regions too.
  • Deployment scopes: you can deploy at resource group, subscription, management group or tenant level, set with targetScope.

How it works, step by step

This is what happens when you deploy a Bicep file:

ARM template to Bicep: how a Bicep deployment runs
  1. The CLI compiles nsg.bicep to ARM JSON and checks types and decorators along the way, and any errors stop it right there.
  2. It then sends the JSON and your parameter values to Resource Manager.
  3. Resource Manager validates the template and works out what order the resources need to go in.
  4. It creates or updates each resource so it matches the template, in incremental mode by default.
  5. Outputs such as the NSG’s ID come back to you in the deployment result.

Since a template describes the end state, deploying the same file a second time changes nothing, and that’s what makes it safe to run from a pipeline.

ARM template to Bicep: exported JSON, decompiled Bicep and clean Bicep

Don’t ever edit the compiled JSON. The .bicep file is your source and the JSON is only a build output, the way an .exe comes out of source code.

Hands-on lab: ARM template to Bicep for an NSG

Before you run any command, double-check it

Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.

Start with a folder for this lesson’s files:

New-Item -ItemType Directory -Path C:\azure-lab\bicep -Force | Out-Null
Set-Location C:\azure-lab\bicep

1Create an NSG by hand, the “click-ops” way

Run this:

az group create --name rg-saat-l41 --location centralindia --tags course=saatvedha-azure lesson=41 -o none
az network nsg create --resource-group rg-saat-l41 --name nsg-saat-demo --tags course=saatvedha-azure lesson=41 -o none
az network nsg rule create --resource-group rg-saat-l41 --nsg-name nsg-saat-demo --name allow-https-in --priority 100 --direction Inbound --access Allow --protocol Tcp --source-address-prefixes Internet --destination-port-ranges 443 -o none

2Export it as an ARM template

Run this, and then open exported.json in VS Code:

az group export --name rg-saat-l41 > exported.json
(Get-Content exported.json).Count

You should get a number somewhere around 70, which is the line count of the exported JSON.

Have a look at what came out: a parameter called networkSecurityGroups_nsg_saat_demo_name, the region hard-coded, the rule written twice (once inside the NSG and again as its own resource), and dependsOn written by hand. Exported templates nearly always look like this.

3Write the clean Bicep version

Save this as nsg.bicep, either in VS Code or with the here-string below, and build it:

$b = @'
@description('Name of the network security group')
param nsgName string = 'nsg-saat-demo'

@description('Azure region for the NSG')
param location string = resourceGroup().location

@description('Priority of the HTTPS rule (100 to 4096)')
@minValue(100)
@maxValue(4096)
param httpsPriority int = 100

resource nsg 'Microsoft.Network/networkSecurityGroups@2024-05-01' = {
  name: nsgName
  location: location
  tags: {
    course: 'saatvedha-azure'
    lesson: '41'
  }
  properties: {
    securityRules: [
      {
        name: 'allow-https-in'
        properties: {
          protocol: 'Tcp'
          sourcePortRange: '*'
          destinationPortRange: '443'
          sourceAddressPrefix: 'Internet'
          destinationAddressPrefix: '*'
          access: 'Allow'
          priority: httpsPriority
          direction: 'Inbound'
        }
      }
    ]
  }
}

output nsgId string = nsg.id
'@
Set-Content -Path nsg.bicep -Value $b
az bicep build --file nsg.bicep
(Get-Content nsg.bicep).Count

You should see this, and a new nsg.json next to it:

38

If the build prints nothing, there were no errors and no warnings. Your 38 lines of Bicep compile to the same kind of JSON that took about 70 lines to export, and this version also has a region parameter, a validated priority and an output.

4Deploy it with a parameters file

Create a .bicepparam file that changes the priority, then deploy:

Set-Content -Path nsg.bicepparam -Value "using 'nsg.bicep'`n`nparam httpsPriority = 200"
az deployment group create --resource-group rg-saat-l41 --name nsg-deploy --parameters nsg.bicepparam --query "{state:properties.provisioningState, nsgId:properties.outputs.nsgId.value}" -o yaml
az network nsg rule list --resource-group rg-saat-l41 --nsg-name nsg-saat-demo --query "[].{name:name, priority:priority, port:destinationPortRange}" -o table

You should see something like this:

nsgId: /subscriptions/.../resourceGroups/rg-saat-l41/providers/Microsoft.Network/networkSecurityGroups/nsg-saat-demo
state: Succeeded
Name            Priority    Port
--------------  ----------  ------
allow-https-in  200         443

The deployment updated the NSG you made by hand. Because the name is the same, Resource Manager changed the rule’s priority rather than creating a second NSG, and from here on this file is your source of truth.

ARM template to Bicep deployment in the portal
rg-saat-l41 deployments: nsg-deploy Succeeded.

5Deploy again and see nothing change

Now run the same deployment again:

az deployment group create --resource-group rg-saat-l41 --name nsg-deploy-2 --parameters nsg.bicepparam --query "properties.provisioningState" -o tsv

You should see this:

Succeeded

Same file and same result, with nothing changed. In Lesson 42 you’ll add what-if, which shows you this before you deploy.

There’s one more habit worth building for every ARM template to Bicep conversion, which is reading the warnings as well as the errors. Say you misspell a property, writing secrityRules instead of securityRules. Bicep still builds, and prints Warning BCP089: The property "secrityRules" is not allowed on objects of type "NetworkSecurityGroupPropertiesFormat". Did you mean "securityRules"?

Because a warning doesn’t stop the build, your pipeline carries on, and depending on how the resource provider handles unknown properties, you could end up with an NSG that’s missing the rules you meant to add. Set your pipeline to fail on any Bicep warning, and fix warnings in VS Code, where they show up as yellow squiggles as you type.

ARM template to Bicep lab: build and deploy with a bicepparam file
A clean build, a deployment using a parameters file, and the rule updated.

✅ Checkpoint: nsg.bicep builds with no warnings, deploys with nsg.bicepparam, and the rule now has priority 200.

Break It, Then Fix It

Both errors below are real Bicep compiler output, though your line numbers may be slightly different.

1Break it: let the decompiler do the work

Let the tool convert the exported template for you:

az bicep decompile --file exported.json

You’ll see something like this:

WARNING: Decompilation is a best-effort process, as there is no guaranteed mapping from ARM JSON to Bicep Template or Bicep Parameters.
...
exported.bicep(14,13) : Error BCP080: The expression is involved in a cycle ("networkSecurityGroups_nsg_saat_demo_name_allow_https_in" -> "networkSecurityGroups_nsg_saat_demo_name_resource").
exported.bicep(52,5) : Error BCP080: The expression is involved in a cycle ("networkSecurityGroups_nsg_saat_demo_name_resource" -> "networkSecurityGroups_nsg_saat_demo_name_allow_https_in").

The export lists the rule twice and the decompiler kept both copies. The inline copy refers to the separate rule’s ID, while the separate rule depends on the NSG, so each one is waiting for the other and Bicep refuses to build.

To fix it, open exported.bicep, delete the line that starts with “id:” inside securityRules, and delete the whole separate securityRules resource at the bottom. Even better, define your rules in one place only, the way nsg.bicep does. Then build:

az bicep build --file exported.bicep

If nothing prints, it built. While you’re in there, rename the long generated names to short ones like nsg.

2Break it: a parameter value Bicep can catch early

Someone sets the HTTPS rule’s priority to 50 so it sits “on top”:

Set-Content -Path nsg.bicepparam -Value "using 'nsg.bicep'`n`nparam httpsPriority = 50"
az deployment group create --resource-group rg-saat-l41 --name nsg-deploy-3 --parameters nsg.bicepparam

You’ll get an error like this:

nsg.bicepparam(3,23) : Error BCP328: The provided value (which will always be less than or equal to 50) is too small to assign to a target for which the minimum allowable value is 100.

NSG priorities go from 100 to 4096. Since nsg.bicep says so with @minValue(100), the mistake gets caught on your laptop before anything reaches Azure. Without that decorator, Resource Manager would reject it later, halfway through the deployment.

To fix it, use a valid value and deploy, then clean up:

Set-Content -Path nsg.bicepparam -Value "using 'nsg.bicep'`n`nparam httpsPriority = 110"
az deployment group create --resource-group rg-saat-l41 --name nsg-deploy-4 --parameters nsg.bicepparam --query "properties.provisioningState" -o tsv
az group delete --name rg-saat-l41 --yes
C:\azure-lab\Find-LabResources.ps1 -Lesson 41

You should see this:

Succeeded
Nothing tagged course=saatvedha-azure is left.
ARM template to Bicep errors: BCP080 cycle and BCP328 parameter value
Real Bicep errors: a decompile cycle and a value below @minValue.

✅ Checkpoint: You fixed a decompile cycle and a parameter caught at build time. Keep the files in C:\azure-lab\bicep for Lesson 42.

This happened at work

The firewall rule that came back every night

During an audit, a software company’s ops team removed an old “allow RDP from anywhere” rule from an NSG. Next morning the rule was back. They removed it a second time, and the morning after that it was back again.

It took some digging to find out why. Months earlier someone had exported the NSG from the portal, decompiled it to Bicep, fixed the errors and added it to a nightly pipeline, and the export had captured every rule as it stood that day, risky one included. So each night the pipeline put the NSG back the way the template said, which is what it was built to do.

What they changed: rules now change only in the Bicep file, through pull requests and review, and portal changes to anything the pipeline manages are blocked with a resource lock and Azure Policy. Exported templates are treated as a first draft and never deployed as they are.

Common mistakes and troubleshooting

MistakeWhat you seeWhat to do
Deploying a decompiled export as-isBCP080 cycles, hard-coded valuesClean it up: one definition per rule, and parameters for names and region.
Typo in a property nameWarning BCP089 (“Did you mean securityRules?”)Read the warnings, and make your pipeline fail on them.
No decorators on parametersBad values fail late in AzureUse @minValue, @maxValue, @allowed.
Editing compiled JSONChanges lost on next buildEdit only the .bicep file.
Changing resources in the portal and in BicepChanges undone at next deployOne source of truth; lock or policy.
Hard-coded regionTemplate only works in one placeUse resourceGroup().location or a parameter.

Interview questions

Click a question to open it. Each one is worded the way an interviewer would ask it, and underneath you’ll find why they ask it and one way you could answer in your own words.

Fresher level

1. What is Bicep?

Why they ask this: To check the basic concept.

How you might answer: It’s a language for deploying Azure resources that compiles to ARM template JSON. It’s shorter, it has type checking and editor support, and it deploys through the same Resource Manager engine.

2. How does Bicep relate to ARM templates?

Why they ask this: They want the link.

How you might answer: Bicep sits on top of ARM. Every Bicep file compiles to an ARM template, and you can decompile ARM JSON back into Bicep, so anything ARM can deploy, Bicep can deploy too.

3. What is a parameters file in Bicep?

Why they ask this: A practical check.

How you might answer: It’s a .bicepparam file that sets values for a Bicep file’s parameters, with a using line that points to the template. At build time Bicep checks those values against the parameter types and decorators.

2–5 years experience

4. You decompiled an exported template and got BCP080 errors. Why?

Why they ask this: A real trap.

How you might answer: Exported templates often define child resources twice, inline and separately, and they reference each other both ways. The decompiler keeps both, which gives you a dependency cycle. I remove one copy, so the rules are either inline or separate child resources, never both.

5. How do you stop bad parameter values reaching Azure?

Why they ask this: They want shift-left thinking.

How you might answer: I’d use decorators like @minValue, @maxValue and @allowed, along with types and user-defined types, .bicepparam files that Bicep checks at build, and a linter step in the pipeline before anything deploys.

6. Incremental vs complete deployment mode: what’s the difference?

Why they ask this: A classic question.

How you might answer: Incremental is the default. It adds and updates what’s in the template and leaves everything else alone. Complete deletes anything in the group that isn’t in the template, which is risky, so these days deployment stacks (Lesson 42) are the safer way to handle deletions.

Senior level

7. How would you move a team from portal changes to Bicep?

Why they ask this: They want change management.

How you might answer: I’d start with new resources only. Existing ones get exported as drafts and cleaned up into modules, templates go into Git with pull requests, deployments run through a pipeline, and locks and policy stop drift. I’d also train people to read what-if output.

8. How do you structure Bicep for a large environment?

Why they ask this: They want design.

How you might answer: Small reusable modules for each resource type, put together in environment files, with a parameter file per environment. For sharing I’d use a module registry or template specs, and keep naming and tagging handled in one central place.

9. What would make you choose Terraform instead of Bicep?

Why they ask this: They want honest trade-offs.

How you might answer: If we needed multi-cloud resources or providers outside Azure, or if the team already had a Terraform estate and the skills for it. For Azure-only work I’d lean towards Bicep, because it supports new resource types from day zero and there’s no state file to look after.

Quick quiz

Q1. What does Bicep compile to?

  1. PowerShell
  2. ARM template JSON
  3. YAML
  4. Terraform
Show answer

B — Resource Manager deploys the compiled JSON.

Q2. Which command converts ARM JSON to Bicep?

  1. az bicep build
  2. az bicep decompile
  3. az deployment group create
  4. az group export
Show answer

B — Decompile is best-effort and may need fixes.

Q3. BCP080 after decompiling means:

  1. A typo
  2. A dependency cycle
  3. A quota problem
  4. A missing region
Show answer

B — Two resources reference each other.

Q4. Which decorator rejects priorities below 100?

  1. @description
  2. @minValue(100)
  3. @secure
  4. @allowed
Show answer

B — @minValue checks numbers at build time.

Q5. A typo like secrityRules gives:

  1. Nothing
  2. Warning BCP089
  3. An Azure outage
  4. A deleted NSG
Show answer

B — Bicep suggests the right name.

Quick recap

You can now turn click-ops into code that you can review and redeploy.

  • Bicep compiles to ARM JSON, and the engine underneath is the same.
  • Treat exported templates as drafts, with duplicated children and hard-coded values.
  • Decompile first, then fix the BCP errors by hand.
  • Decorators and .bicepparam catch bad values before Azure sees them.
  • The .bicep file is your source of truth, so never edit the JSON.

Next lesson

Lesson 42: Bicep in practice: modules, what-if, deployment stacks → You split templates into modules, preview changes with what-if and manage deletions with deployment stacks.

Further reading: ARM template to Bicep

Want to go deeper into ARM template to Bicep? See Microsoft’s What is Bicep? and Decompile ARM template JSON to Bicep. You can also see the full plan for this course on the Azure Cloud Administration course page.

Scroll to Top

This website uses cookies

We use a few cookies to keep this site working. If you allow it, we also use Google Analytics to count visits so we can improve our lessons. You can accept all, deny the optional ones, or choose what to allow.