From ARM templates to Bicep
-
Phase 0: Before you start
-
Phase 1: The foundation
-
Phase 2: Day-to-day operations
-
Phase 3: Enterprise architecture
-
Phase 4: Troubleshooting step by step
-
Phase 5: Final project and career
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.
| Time | You need | Cost | By the end you can |
|---|---|---|---|
| About 45 minutes | The CLI with Bicep (Lesson 3), VS Code with the Bicep extension | No cost: a network security group only | Read 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 | |
|---|---|---|
| File | azuredeploy.json | main.bicep |
| References | [parameters(‘x’)], [resourceId(…)] | x, nsg.id |
| Dependencies | dependsOn written by hand | Worked out from references |
| Errors | Mostly at deployment | Most at build time, in VS Code |
| Parameters | parameters.json | .bicepparam with type checking |
| Deployed as | JSON | Compiled to JSON first |
- Same engine: Bicep doesn’t have a runtime of its own.
az bicep buildturns a .bicep file into ARM JSON, and it’s Resource Manager that deploys it. - Decorators: you use
@description,@minValue,@maxValue,@allowedand@secureto document parameters and validate them. - Decompile:
az bicep decompileconverts 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:
- The CLI compiles
nsg.bicepto ARM JSON and checks types and decorators along the way, and any errors stop it right there. - It then sends the JSON and your parameter values to Resource Manager.
- Resource Manager validates the template and works out what order the resources need to go in.
- It creates or updates each resource so it matches the template, in incremental mode by default.
- 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.
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\bicep1Create 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 none2Export 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).CountYou 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).CountYou should see this, and a new nsg.json next to it:
38If 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 tableYou 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 443The 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.

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 tsvYou should see this:
SucceededSame 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.

✅ 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.jsonYou’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.bicepIf 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.bicepparamYou’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 41You should see this:
Succeeded
Nothing tagged course=saatvedha-azure is left.
✅ 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
| Mistake | What you see | What to do |
|---|---|---|
| Deploying a decompiled export as-is | BCP080 cycles, hard-coded values | Clean it up: one definition per rule, and parameters for names and region. |
| Typo in a property name | Warning BCP089 (“Did you mean securityRules?”) | Read the warnings, and make your pipeline fail on them. |
| No decorators on parameters | Bad values fail late in Azure | Use @minValue, @maxValue, @allowed. |
| Editing compiled JSON | Changes lost on next build | Edit only the .bicep file. |
| Changing resources in the portal and in Bicep | Changes undone at next deploy | One source of truth; lock or policy. |
| Hard-coded region | Template only works in one place | Use 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?
- PowerShell
- ARM template JSON
- YAML
- Terraform
Show answer
B — Resource Manager deploys the compiled JSON.
Q2. Which command converts ARM JSON to Bicep?
- az bicep build
- az bicep decompile
- az deployment group create
- az group export
Show answer
B — Decompile is best-effort and may need fixes.
Q3. BCP080 after decompiling means:
- A typo
- A dependency cycle
- A quota problem
- A missing region
Show answer
B — Two resources reference each other.
Q4. Which decorator rejects priorities below 100?
- @description
- @minValue(100)
- @secure
- @allowed
Show answer
B — @minValue checks numbers at build time.
Q5. A typo like secrityRules gives:
- Nothing
- Warning BCP089
- An Azure outage
- 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.
