Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 21 of 47
❮Prev Next❯

Deploy, Export and Convert Templates to Bicep

Module 3: Compute ⏱ 11 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    30-second answer

    Deploy a template to a resource group with az deployment group create --template-file main.bicep (or New-AzResourceGroupDeployment, or Deploy a custom template in the portal). Preview first with what-if. The default mode is Incremental, which adds and updates resources; Complete also deletes resources in the group that the template doesn't define. To get a template from what already exists, use Export template on a resource group or resource (or az group export), or download one from Deployments history. Convert ARM JSON to Bicep with az bicep decompile.

    Simulate it » No Azure account needed

    Exam objective: 3.1.4 Deploy resources by using an Azure Resource Manager template or a Bicep file. 3.1.5 Export a deployment as an Azure Resource Manager template or convert an Azure Resource Manager template to a Bicep file. (Skills measured as of April 17, 2026)

    Simulations

    Feel it before you read it. No account needed, nothing leaves this page.

    Azure portal: Deployment history, export template and convert to Bicep Open deployment history, export the group and convert it to Bicep.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading the portal…

    Open <strong>Resource groups</strong> and select <strong>rg-contoso-prod</strong>.

    👆 Click the glowing item in the portal to continue

    Read the steps as text
    1. Open Resource groups and select rg-contoso-prod.
    2. Under Settings, open Deployments. Every template deployment into this group is recorded here.
    3. Each row keeps the template, inputs and outputs. Open storage. From here you can download its template or Redeploy it.
    4. Back on the resource group, Automation › Export template generates a template from the current resources. The ARM Template tab is JSON; the Bicep tab shows the same thing converted.
    5. The Bicep version is shorter and easier to review. To convert a JSON file yourself, use az bicep decompile in Cloud Shell.
    6. Export, decompile, then preview with what-if: ~ means modify, + create, - delete. Nothing changes until you deploy.
    7. Deploy with Incremental (the default: add and update). Complete also deletes anything in the group that the template doesn't list, so run what-if first and think twice.

    🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.

    😟 THE PROBLEM

    A Complete-mode deployment deleted a database nobody had put in the template.

    😊 THE SOLUTION

    Preview with what-if and know what each deployment mode does.

    • Surprise deletions✓ what-if before Complete mode
    • No template for old resources✓ Export template
    • JSON is hard to maintain✓ az bicep decompile
    🛠️ Solved with: Deployment modes, what-if and export

    Start with a question

    How do you rebuild a room exactly as it was, without throwing out what someone else put there?

    You’ve got the floor plan for an office. Put the furniture back where the plan says and leave everything else alone: that’s one way. Make the room match the plan exactly, so anything not on the plan goes in the skip: that’s another.

    Template deployments work the same. Incremental mode adds and fixes what’s on the plan. Complete mode also throws out what isn’t. And when you only have the room and no plan, Export template draws one for you.

    Explain it like I’m 10

    The technical explanation

    Deploy

    ToolCommand or path
    Azure CLIaz deployment group create -g rg-contoso-prod --template-file main.bicep --parameters storageName=stcontosologs
    PowerShellNew-AzResourceGroupDeployment -ResourceGroupName rg-contoso-prod -TemplateFile main.bicep -storageName stcontosologs
    PortalSearch Deploy a custom template › Build your own template in the editor (ARM JSON)
    Other scopesaz deployment sub create, az deployment mg create, az deployment tenant create (they need --location)

    The CLI compiles Bicep for you. PowerShell needs the Bicep CLI installed. Parameters can come from the command line (key=value), a JSON parameters file (--parameters @main.parameters.json) or a .bicepparam file. The deployment name defaults to the template file name, and each one is kept in the resource group’s Deployments history (up to 800 per group; older entries are removed automatically).

    Preview with what-if

    az deployment group what-if -g rg-contoso-prod --template-file main.bicep --parameters storageName=stcontosologs
    #  ~ Microsoft.Storage/storageAccounts/stcontosologs
    #    ~ sku.name: "Standard_LRS" => "Standard_ZRS"
    # Resource changes: 1 to modify.

    The symbols are + create, ~ modify, - delete, = no change, * ignore. PowerShell uses -WhatIf on the same cmdlet. az deployment group create --confirm-with-what-if shows the preview and asks before deploying.

    Incremental vs Complete

    Incremental (default)Complete
    Resources in the templateCreated or updatedCreated or updated
    Resources in the group but not in the templateLeft aloneDeleted
    How to chooseNothing to add--mode Complete / -Mode Complete
    Use it forAlmost everythingA group that only this template owns

    Two details catch people out. In both modes a resource that is in the template gets the template’s properties, so a setting someone changed in the portal is reverted. And the portal’s custom deployment always runs Incremental. A CanNotDelete lock on a resource stops Complete mode from removing it.

    Export what already exists

    • Resource group or resource › Automation › Export template: generates a template from the current state, with ARM Template and Bicep tabs and an Include parameters option. Download it or select Deploy.
    • Deployments history: open a past deployment and view or download the exact template and inputs it used.
    • CLI / PowerShell: az group export -n rg-contoso-prod > exported.json, az deployment group export -g rg-contoso-prod -n storage (one deployment’s template), Export-AzResourceGroup, Save-AzResourceGroupDeploymentTemplate.

    Exported templates hard-code names and values, can’t include every resource type or property, and are limited to a few hundred resources per export. Treat them as a draft.

    Convert to Bicep

    az bicep decompile --file exported.json   # creates exported.bicep (best effort, read the warnings)
    az bicep build --file main.bicep          # creates main.json (what Resource Manager deploys)
    Architect level Deployment stacks and the end of Complete mode

    Microsoft recommends deployment stacks over Complete mode for managing a set of resources as a unit. A stack (az stack group create) remembers which resources it created. When you remove one from the template, the stack can delete or detach it (--action-on-unmanage), and deny settings can stop people changing managed resources outside the stack. That gives you Complete mode’s clean-up without deleting things the template never owned. The exam still asks about Incremental and Complete, so learn those first.

    Real-world business scenario

    Healthcare

    Fabrikam Health (fictional)

    The problem
    Years of portal clicks left a production resource group nobody could rebuild, and a test of Complete mode in staging deleted a shared Key Vault.
    What they used
    The team exported the production group, decompiled it with az bicep decompile, turned names into parameters and checked every deployment with what-if. They kept Incremental mode and put CanNotDelete locks on shared resources.
    Why that choice
    Export gave them a starting template for resources that were never scripted, and what-if showed every change before it happened.
    The result
    Production can be rebuilt from a reviewed Bicep file, and no deployment has deleted anything by surprise since.

    When to use it and when not to

    ✓ Use it when…

    • Incremental mode for routine deployments into shared resource groups.
    • what-if before every production deployment, and always before Complete mode.
    • Export template to capture resources that were built by hand.

    ✕ Think twice when…

    • Complete mode in a resource group that other people or templates also use.
    • Redeploying an exported template without cleaning it up first.

    ↔ Alternatives to consider

    • Deployment stacks to manage and clean up a set of resources safely.
    • Template specs to store versioned templates in Azure for others to deploy.
    • GitHub Actions or Azure Pipelines to run what-if and deploy on every merge.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    Test yourself with exercises

    5 original practice questions in the AZ-104 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.

    Question 1

    Question 1 of 5

    Resource group RG1 contains a storage account named st1 and a virtual network named VNet1. You deploy a template to RG1 that defines only st1. You do not specify a deployment mode.

    What happens to VNet1?

    Question 2

    Question 2 of 5

    You need to review the resources that a Bicep deployment will create, modify, or delete in resource group RG1 without making any changes. Which command should you run?

    Question 3

    Question 3 of 5

    Several resources in RG1 were created manually in the Azure portal. You must create a template that represents the current state of RG1 with the least administrative effort.

    What should you use?

    Question 4

    Question 4 of 5

    You have an ARM template named azuredeploy.json. You need to convert it to a Bicep file. Which command should you run?

    Question 5

    Question 5 of 5 · Select 2

    You must deploy a Bicep file named main.bicep to resource group RG1. Any resources in RG1 that are not defined in main.bicep must be removed.

    Which two commands meet the requirement? Each correct answer presents a complete solution.

    Interview preparation

    Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.

    Beginner Which command deploys a Bicep file to a resource group?

    Model answer

    az deployment group create --resource-group rg-name --template-file main.bicep, with --parameters for the inputs. In PowerShell it's New-AzResourceGroupDeployment with -TemplateFile. There are matching sub, mg and tenant commands for other scopes.

    Intermediate What's the difference between Incremental and Complete mode?

    Model answer

    Incremental is the default. It creates or updates whatever is in the template and doesn't touch anything else in the resource group. Complete makes the group match the template exactly, so anything not in the template gets deleted. I'd only use Complete with what-if first and probably a delete lock on anything precious.

    Experienced developer Why shouldn't you redeploy an exported template as it is?

    Model answer

    Export captures what exists now with names, IDs and values hard-coded. Some resource types and properties can't be exported, and it's capped at a number of resources. So I treat it as a starting point: decompile to Bicep, turn the hard-coded values into parameters, remove read-only properties, then test it with what-if.

    Scenario A teammate wants to run a Complete-mode deployment on the production resource group to tidy it up. What do you do?

    Model answer

    I'd run what-if with --mode Complete first and read every line starting with a minus sign, because those get deleted. If anything there is in use, either it goes into the template or we stay in Incremental mode and remove leftovers deliberately.

    Quick revision

    Key points

    • CLI az deployment group create, PowerShell New-AzResourceGroupDeployment, portal Deploy a custom template.
    • Default mode is Incremental. Complete deletes resources not in the template.
    • what-if previews - + create, ~ modify, - delete, = no change.
    • Export template from a resource group or resource, or az group export. Deployment history keeps each template used.
    • az bicep decompile converts JSON to Bicep; az bicep build compiles Bicep to JSON.

    Important terminology

    Deployment
    One run of a template against a scope. It's recorded in the scope's deployment history with its template, parameters and outputs.
    Incremental mode
    The default deployment mode. Resources in the template are created or updated; others in the resource group are left alone.
    Complete mode
    A deployment mode that also deletes resources in the resource group that aren't in the template.
    what-if
    A preview of the changes a deployment would make (create, modify, delete, no change) without making them.
    Export template
    A portal and CLI feature that generates an ARM template (and a Bicep view) from existing resources.
    az bicep decompile
    The command that converts an ARM JSON template into a Bicep file, on a best-effort basis.
    Parameters file
    A JSON or .bicepparam file that supplies parameter values so they don't have to be typed on the command line.

    Common mistakes

    • Running Complete mode without what-if and deleting resources someone else added.
    • Assuming an exported template captures every property and can be redeployed unchanged.

    Exam tips

    • "Delete resources not in the template" = Complete mode.
    • "Preview changes without deploying" = what-if.
    • "Convert an ARM template to Bicep" = az bicep decompile.

    Five quick revision questions

    1. 1.What is the default deployment mode?Show

      Incremental.

    2. 2.Which command previews a deployment's changes?Show

      az deployment group what-if.

    3. 3.Which command exports a resource group as an ARM template?Show

      az group export.

    4. 4.Which PowerShell cmdlet deploys a template to a resource group?Show

      New-AzResourceGroupDeployment.

    5. 5.Where in the portal do you see the templates used for past deployments?Show

      The resource group's Deployments blade.

    Official references

    Finished this lesson? Tick it off. Your progress is saved in this browser.

    Next up: Create Virtual Machines and Manage VM Sizes

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.