If you have ever built Azure infrastructure by clicking through the portal, you already know the problem. The first environment takes an afternoon, the second takes just as long, and nobody can say exactly what is different between them. Azure Bicep fixes that. It is a domain-specific language for deploying Azure resources, and it lets you describe the infrastructure you want in a short, readable file, then deploy that file again and again with identical results.
This tutorial takes you from zero to a working deployment. You will install the tools, write a template that creates a storage account, add parameters and modules, preview changes before they happen, and wire the result into a pipeline. Everything here uses the Azure CLI, so it works the same on Windows, macOS and Linux. You need an Azure subscription and a resource group to follow along; every command that creates something billable is flagged, and the clean-up step at the end removes it all.
What Is Azure Bicep and Why Use It?
Bicep is a declarative language that sits on top of Azure Resource Manager (ARM). You declare the resources you want — a storage account, a virtual network, a web app — and Azure Resource Manager works out the order to create them in. A Bicep file compiles to an ARM JSON template behind the scenes, so anything that is valid in an ARM template is valid in Bicep. The difference is that Bicep is far shorter and easier to read: no bracketed expressions, no deeply nested JSON, and symbolic names instead of long resource IDs.
Three properties make Bicep worth learning. First, it is idempotent. Deploy the same file twice and the second run changes nothing, because Azure compares the desired state with what already exists. Second, it needs no state file. Azure itself stores the state of your resources, so there is no state file to lock, back up or accidentally delete — a real contrast with tools that keep state locally. Third, it supports every Azure resource type and API version on day one, because it is a transparent layer over ARM templates rather than a separate provider that has to catch up.
Bicep also handles orchestration for you. When one resource references another by its symbolic name, Bicep automatically creates an implicit dependency, so the referenced resource is deployed first. You rarely need to write explicit dependency declarations, and when resources are independent, Resource Manager deploys them in parallel, which makes large deployments finish faster than a sequence of manual steps.
| Approach | Language | State file | Cloud scope | Best for |
|---|---|---|---|---|
| Bicep | Bicep DSL | None — Azure stores state | Azure only | Azure-only teams who want the shortest path to repeatable deployments |
| ARM JSON templates | JSON | None — Azure stores state | Azure only | Teams with existing JSON templates or generated templates |
| Terraform | HCL | Yes — local or remote backend | Multi-cloud | Teams managing Azure alongside AWS, GCP or on-premises systems |
None of these is wrong. If your whole estate is Azure, Bicep is usually the fastest to learn and the least to maintain. If you manage several clouds with one workflow, Terraform earns its state file. Many teams use both — Bicep for Azure platform resources and Terraform for the multi-cloud parts — and that is a reasonable choice rather than a contradiction. Microsoft’s own overview, What is Bicep?, sets out the same benefits: concise syntax, type safety, idempotent deployments and no state file to manage. Our Terraform tutorial for beginners covers that path in the same hands-on style, so you can compare the two from real examples rather than marketing claims.
Before you write a line of code, it helps to know where the guardrails are. Bicep files are plain text, so they belong in source control with the same review process as application code. A pull request that changes a template should show a what-if preview, just as a pull request that changes application code shows test results. That single habit — never deploying a template that nobody reviewed — prevents more incidents than any amount of clever syntax. The Bicep Playground, linked from the Microsoft Learn overview, lets you try syntax in the browser without installing anything, which is a good way to test an expression before you paste it into a real file.
Setting Up Your Bicep Environment
You need two things: the Azure CLI and an editor with Bicep support. Microsoft recommends Visual Studio Code with the Bicep extension, which gives you IntelliSense, syntax validation and one-click deployment. Install VS Code, open the Extensions tab, search for “bicep” and install the extension published by Microsoft. Visual Studio has its own Bicep extension if that is your editor of choice. The full setup steps, including the manual install for Azure PowerShell and the download for air-gapped clouds, are on Microsoft Learn’s Install Bicep tools page.
The Azure CLI installs the Bicep CLI automatically the first time you run a command that needs it, but Microsoft documents a minimum Azure CLI version of 2.20.0, so check yours first. If you use Azure PowerShell instead, you need version 5.6.0 or later, and you must install the Bicep CLI manually — PowerShell does not fetch it for you.
az --version
az login
az account show --query "{subscription:name, id:id}" --output table
az bicep version
az bicep upgrade
Run az login and sign in with the account that owns your subscription. Then confirm which subscription is active with az account show, because deploying to the wrong subscription is the most common beginner mistake and the hardest to notice until the bill arrives. If you manage several subscriptions, set the right one with az account set --subscription "Your Subscription Name" before you deploy anything.
Create a resource group to hold the practice resources. Resource groups are the deployment boundary for most Bicep files: you deploy into a group, and deleting the group deletes everything inside it, which makes clean-up trivial.
az group create --name rg-bicep-demo --location uksouth
If az bicep version reports an error, the CLI has not installed Bicep yet. Run az bicep install explicitly, then try again. In an air-gapped environment you can download the Bicep CLI directly, but for a normal workstation the automatic install is the path Microsoft documents.
Your First Bicep File: A Storage Account
Create a file called main.bicep. Every Bicep file is built from four building blocks: parameters, variables, resources and outputs. This first example uses a parameter and a single resource. It deploys a storage account, which is the simplest real Azure resource and a good first deployment because it is cheap and fast to create.
param location string = resourceGroup().location
param storageAccountName string = 'toylaunch${uniqueString(resourceGroup().id)}'
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-05-01' = {
name: storageAccountName
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
properties: {
accessTier: 'Hot'
}
}
Read it line by line. The param declarations define inputs: location defaults to the resource group’s location, and storageAccountName builds a globally unique name by appending a hash of the resource group ID to a prefix, because storage account names must be unique across all of Azure and contain only lowercase letters and numbers. The resource declaration names the resource type and API version — Microsoft.Storage/storageAccounts@2023-05-01 — gives it a symbolic name (storageAccount) that other parts of the file can reference, and sets its properties.
Before you deploy, compile the file to check for syntax errors. The Bicep CLI converts it to an ARM JSON template, which you can inspect if you are curious about what Azure actually receives.
az bicep build --file main.bicep
Now deploy it into the resource group you created. The deployment name is just a label in your deployment history, so make it descriptive.
az deployment group create \
--name first-bicep-deploy \
--resource-group rg-bicep-demo \
--template-file main.bicep
Check the result in the portal or with az storage account list --resource-group rg-bicep-demo --output table. Then run the same deployment command again and watch the output: the second run reports no changes, because the deployment is idempotent. That is the behaviour you want from infrastructure as code — running the same file twice is safe, not destructive. If you want to see what Azure recorded, run az deployment group show --resource-group rg-bicep-demo --name first-bicep-deploy and look at the properties section: it lists the template, the parameters that were supplied, the outputs, and the state of every resource the deployment touched. That deployment history is also where you go when something fails, because the error message there is usually more detailed than the one printed to your terminal.
When you are finished practising, remove everything with a single command. Deleting the resource group deletes the storage account and every other resource inside it, which is exactly why practice deployments belong in a disposable group rather than one shared with real workloads:
az group delete --name rg-bicep-demo --yes --no-wait
Parameters, Variables and Outputs
Hard-coded values make a template usable exactly once. Parameters, variables and outputs make it reusable across environments. Parameters are inputs supplied at deployment time. Variables are values computed inside the file. Outputs return values — such as a resource ID or endpoint — to whoever or whatever called the deployment.
Give every parameter a type and, where it helps, a decorator that constrains it. Types are string, int, bool, array and object, plus secureString and secureObject for secrets. The @allowed decorator restricts a parameter to a list of values, which stops a typo from deploying a premium SKU when you meant standard. The @description decorator documents what the parameter is for, and it shows up in tooling, so write it for every parameter a teammate might have to fill in.
@description('The environment this deployment targets.')
@allowed([
'dev'
'test'
'prod'
])
param environment string = 'dev'
@description('Administrator password. Never commit a real value.')
@secure()
param adminPassword string
var storageName = 'st${environment}${uniqueString(resourceGroup().id)}'
var tags = {
environment: environment
managedBy: 'bicep'
}
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-05-01' = {
name: storageName
location: resourceGroup().location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
tags: tags
}
Two rules matter here. First, never put a secret in a parameter file that is committed to source control. Mark secrets with @secure() so their values are not logged or returned in deployment outputs, and pass them at deployment time or from Azure Key Vault. Bicep can read a secret from Key Vault at deployment time with the getSecret() function, which keeps the value out of your repository entirely.
Second, keep environment differences in parameter files, not in copies of the template. A parameter file is a JSON file that supplies values for one environment, so you keep one main.bicep and a main.dev.bicepparam or parameters.dev.json per environment. Deploy with --parameters @parameters.dev.json and the same template produces a development environment or a production one depending only on the file you point at.
Outputs close the loop. When a later step in a pipeline needs the storage account name, output it from the template instead of reconstructing it with string manipulation:
output storageAccountName string = storageAccount.name
output storageAccountId string = storageAccount.id
Outputs are also how modules talk to each other, which is the subject of the next section.
Modules: Reusing Bicep Code
A module is a Bicep file that another Bicep file deploys. Modules are how you stop copying the same virtual network or storage account definition into every project. You write the resource once, expose its inputs as parameters and its useful values as outputs, then reference it from a parent file.
Start by moving the storage account into modules/storage.bicep. The file looks almost identical to the standalone version, except it declares an output for the account name. Then the parent file, main.bicep, calls it:
param location string = resourceGroup().location
param environment string = 'dev'
module storage 'modules/storage.bicep' = {
name: 'storageDeploy'
params: {
location: location
environment: environment
}
}
output storageAccountName string = storage.outputs.storageAccountName
Modules can be scoped to a resource group, a subscription, a management group or a tenant, so a single parent file can deploy a resource group at subscription scope and then deploy resources inside it. They can also be published to a private module registry — Azure Container Registry doubles as a Bicep registry — so teams share versioned modules the same way they share container images. Pin a version when you reference a registry module, exactly as you would pin an image tag, so a teammate’s update does not silently change your next deployment.
Two patterns cover most real projects. The first is a module per resource type: one module for a virtual network, one for a key vault, one for an app service plan. The second is a module per reusable stack: a “web app with database” module that wires several resources together and exposes only the handful of parameters that vary. Start with the first pattern; move to the second when you find yourself deploying the same three resources together for the third time.
Loops and conditions keep modules small. A for loop creates one subnet per entry in an array, and an if condition deploys a resource only in production. Here is a virtual network whose subnets come from a loop, so adding a fourth subnet means adding one line to an array instead of copying a whole block:
param subnetNames array = [
'web'
'app'
'data'
'AzureBastionSubnet'
]
resource vnet 'Microsoft.Network/virtualNetworks@2023-05-01' = {
name: 'vnet-demo'
location: resourceGroup().location
properties: {
addressSpace: {
addressPrefixes: [
'10.0.0.0/16'
]
}
subnets: [for (name, i) in subnetNames: {
name: name
properties: {
addressPrefix: '10.0.${i}.0/24'
}
}]
}
}
resource publicIp 'Microsoft.Network/publicIPAddresses@2023-05-01' = if (environment == 'prod') {
name: 'pip-bastion-demo'
location: resourceGroup().location
sku: {
name: 'Standard'
}
properties: {
publicIPAllocationMethod: 'Static'
}
}
resource bastion 'Microsoft.Network/bastionHosts@2023-05-01' = if (environment == 'prod') {
name: 'bastion-demo'
location: resourceGroup().location
properties: {
ipConfigurations: [
{
name: 'bastionConfig'
properties: {
subnet: {
id: vnet.properties.subnets[3].id
}
publicIPAddress: {
id: publicIp.id
}
}
}
]
}
}
Notice two things in that example. The loop builds each subnet’s address prefix from its index, so the web subnet becomes 10.0.0.0/24, the app subnet 10.0.1.0/24 and the data subnet 10.0.2.0/24, with no repeated code. And the bastion host is wrapped in an if condition, so it only deploys when the environment is production — a cheap way to keep development environments small without maintaining a second template. When a loop grows complicated, move it into its own module — readability is the point of Bicep, and a file nobody can read is worse than the JSON it replaced.
Deploying Safely: What-If, Validation and Scopes
The most important Bicep command for a beginner is the one that deploys nothing. az deployment group what-if previews exactly what a deployment would create, modify or delete, and which properties would change. Run it before every deployment, in every environment, without exception. The output colour-codes changes — creates, modifies and deletes — so a destructive change is visible before it happens rather than after.
az deployment group what-if \
--resource-group rg-bicep-demo \
--template-file main.bicep \
--parameters environment=prod
Understand the two deployment modes. Incremental is the default: resources in the template are created or updated, and anything already in the resource group but not in the template is left alone. Complete mode deletes resources in the group that are not in the template. Complete mode is powerful for keeping an environment exactly in sync with code, and dangerous for the same reason — a template that omits a resource deletes it. Never use complete mode on a resource group that contains resources managed outside the template, and never use it for the first time on a production group.
Validate a template without deploying it by using what-if, or by running a validation-only deployment. In a pipeline, add a az bicep build step to catch syntax errors, a what-if step to catch unintended changes, and only then the real deployment. The Bicep linter, built into the VS Code extension, also flags common problems as you type — unused parameters, hard-coded secrets, and API versions that are out of date — so fix warnings before they reach a pull request. A minimal pipeline sequence looks like this: build the template, run what-if against the target resource group and fail the pipeline if the preview shows a delete you did not expect, then deploy with the environment’s parameter file. Keep the deployment’s output — the deployment name, the template hash and the what-if result — as a build artefact, because that is the audit trail that shows exactly what was deployed, when, and by whom. If a deployment ever goes wrong, the same history lets you redeploy the previous known-good template instead of guessing what changed.
Deployment scopes decide where resources land. Most files deploy at resource-group scope, but you can target a subscription to create resource groups themselves, or a management group or tenant for policy and role assignments. The scope is set in the file with targetScope or on the command line with az deployment sub create instead of az deployment group create. Mixing scopes in one file is a common source of confusing errors, so keep one file to one scope and use modules when you need to cross a boundary.
Bicep vs Terraform, and the Errors You Will Meet
The honest comparison is about scope, not quality. Bicep is Azure-only, has no state file, and gets day-one support for new Azure features because it is built by the Azure team. Terraform is multi-cloud, keeps its own state, and has a larger ecosystem of providers and modules. If you work only in Azure, Bicep is less to operate. If you work across clouds, Terraform is the single workflow. Many teams use both — Bicep for Azure platform resources and Terraform for the multi-cloud parts — and that is a reasonable choice rather than a contradiction. Our Azure DevOps pipeline tutorial shows how to run Bicep validation and deployment as pipeline stages, so the template gets the same review and testing discipline as application code.
Now the errors. InvalidTemplateDeployment with a message about a storage account name usually means the name breaks the naming rules — lowercase letters and numbers only, between 3 and 24 characters. ResourceNotFound during a deployment usually means a module references a resource in a different resource group without a scope, or a symbolic name is used before the resource it points to is declared. DeploymentActive means another deployment is already running against the same resource group; wait for it or cancel it before retrying.
The most confusing error is a deployment that succeeds but changes nothing you expected. That is almost always a parameter file pointing at the wrong environment, or a default parameter value silently winning because the parameter file did not override it. Check the deployment inputs in the portal — every deployment records the exact parameters it received — before you assume the template is wrong.
Finally, remember that Bicep is also a career skill, not just a tool. Infrastructure as code appears in Azure administrator and DevOps engineer roles, and the certification path around it is changing: exam AZ-400 and the DevOps Engineer Expert certification retire on 1 February 2027, and the successor is exam AZ-401, which leads to the Agentic DevOps Engineer Expert certification. Our Azure certification roadmap for 2026 explains the new path, including the AZ-401 plus GH-300 or AZ-104 combination, so you can plan study around the retirement date rather than discovering it after booking.
Frequently Asked Questions
Is Bicep free to use?
Yes. Bicep itself costs nothing — Microsoft states that you do not pay for premium capabilities, and support is included. You pay only for the Azure resources your templates create, such as storage accounts and virtual machines, at their normal rates.
Do I need to learn ARM JSON before Bicep?
No. Bicep is designed so you never have to write JSON templates by hand. It helps to know that Bicep compiles to ARM JSON, because that explains error messages and the deployment history you see in the portal, but you can be productive in Bicep without writing a line of JSON.
Does Bicep replace Terraform?
Not exactly. Bicep replaces ARM JSON templates for Azure-only work, and it is the simplest choice there. Terraform remains the better fit when you manage several clouds with one tool, because Bicep only targets Azure. Many engineers learn both and choose per project.
What is the difference between what-if and a real deployment?
What-if previews the changes a deployment would make — creates, modifies and deletes — without changing anything. A real deployment applies them. Run what-if first, read the output, and only then deploy, especially in production.
Can I convert my existing ARM JSON templates to Bicep?
Yes. The Bicep CLI can decompile a JSON template with az bicep decompile --file template.json. The result usually needs tidying — decompiled files are more verbose than hand-written Bicep — but it is a fast starting point for migrating existing templates.
Conclusion
You now have the full Bicep workflow: install the tools, write a template, preview it with what-if, deploy it, and organise it into modules that a team can reuse. The next step is to convert one real piece of your own infrastructure — a storage account, a virtual network, a small web app — into a Bicep file and deploy it to a test resource group. Keep the file in source control, add what-if to your pipeline, and delete the practice resource group when you are done with az group delete --name rg-bicep-demo --yes --no-wait. The habit that matters is not the syntax; it is deploying from code, previewing before you apply, and never clicking through the portal for something you will need to build twice.



