> ## Content Index
> Fetch the complete content index at: https://www.techielass.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Getting Started with Azure Bicep
- URL: https://www.techielass.com/getting-started-with-azure-bicep/
- Published: 2022-03-28T07:01:00.000Z
- Updated: 2023-12-07T14:28:54.000Z
- Description: Join me as I look to start learning Azure Bicep. I walk through creating a template and deploying it to Azure.
- Author: Sarah Lean
- Tags: Azure Bicep, Azure

I've been spending a lot of time recently digging into [Azure Bicep](https://docs.microsoft.com/azure/azure-resource-manager/bicep/?WT.mc%5Fid=AZ-MVP-5004737&ref=techielass.com) and learning how to deploy Azure resources using this new domain-specific language. 

## What is Azure Bicep?

Azure Bicep is a declarative language that will help you deploy your Azure resources. I've also heard Azure Bicep described as an Infrastructure as Code (IaC) tool. 

Azure Bicep is an evolution from Azure Resource Manager (ARM) templates that we've had for many years. You don't need any prior knowledge of ARM templates to get started with Azure Bicep. 

## What do you need to get started with Azure Bicep?

You'll need [Visual Studio Code](https://code.visualstudio.com/?ref=techielass.com), the [Bicep extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep&ref=techielass.com) and [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli?WT.mc%5Fid=AZ-MVP-5004737&ref=techielass.com) or [Azure PowerShell](https://docs.microsoft.com/powershell/azure/install-az-ps?WT.mc%5Fid=AZ-MVP-5004737&ref=techielass.com), all installed locally. These tools will help you write, visualise and deploy your resources via an Azure Bicep template. 

## Azure Bicep Templates

Azure Bicep templates have the file extension **.bicep** When you use [Visual Studio Code](https://code.visualstudio.com/?ref=techielass.com) and the [Bicep extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep&ref=techielass.com) you'll be given help and warned about syntax errors or given help to author the template. 

There are key areas to an Azure Bicep template, we're going to take a simple Azure Virtual Network template as an example to work on and deploy today. 

```bicep
param location string = resourceGroup().location

resource virtualNetwork 'Microsoft.Network/virtualNetworks@2021-05-01' = {
  name: 'sarahs-network'
  location: location
  tags: {
    Owner: 'Sarah'
    Purpose: 'Tutorial'
  }
  properties: {
    addressSpace: {
      addressPrefixes: [
        '20.0.0.0/16'
      ]
    }
    subnets: [
      {
        name: 'servers'
        properties: {
          addressPrefix: '20.0.0.0/24'
        }
      }
      {
        name: 'desktops'
        properties: {
          addressPrefix: '20.0.1.0/24'
        }
      }
      {
        name: 'resources'
        properties: {
          addressPrefix: '20.0.2.0/24'
        }
      }
    ]
  }
}

```

Let's look closely at some key parts of this resource definition:

- The first line is a defining the parameter for our resources' location. We've set it so the resource is deployed in the same Azure location as our resource group.
- The **resource** keyword at the start tells Bicep that you're defining a resource.
- The next part is a *symbolic name*. In the example, the resource's symbolic name is **virtualNetwork**. Symbolic names are used within Bicep to refer to the resource.
- We then have the resource type and API version of the resource - **Microsoft.Network/virtualNetworks@2021-05-01\.** This tells Bicep we're declaring a Virtual Network and then which version of the API to use.
- We've then declared the resource name in the second line, we're calling this Virtual Network "*Sarahs-Network".*
- We then set information like *location, tags* for the resource.
- We then start to declare information about the Virtual Network and the subnets we want to be deployed.

We've kept the template simple in this example, but you could declare things like DHCP options, DDOS Protection, BGP, encryption and much more. To find out more about what you can declare for a Virtual Network [check out the documentation here](https://docs.microsoft.com/azure/templates/microsoft.network/virtualnetworks?tabs=bicep&WT.mc%5Fid=AZ-MVP-5004737&ref=techielass.com). 

## Visualise your Azure Bicep template

As part of the [Azure Bicep extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep&ref=techielass.com) you have the ability to visualise your template. You can press CTRL + K V on a Windows machine or you can select the visualise button in the right-hand corner. 

![Azure Bicep visualiser button inside Visual Studio Code](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2022/03/bicepvisualiser.png)

Azure Bicep visualiser button inside Visual Studio Code

Because we have a simple template the visualiser doesn't add much value however, if we visualise a Bicep template with nested templates then we can see the power of the visualiser. 

![Azure Bicep templates visualised within Visual Studio Code](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2022/03/bicepvisualisedtemplate.png)

Azure Bicep templates visualised within Visual Studio Code

## Deploy an Azure Template using Azure CLI

The first thing we need to do before deploying our template is make sure we are logged into Azure CLI on our local machine. We type in the following command that will log us into our relevant Azure subscription. 

```bash
az login

```

Now we need to create an Azure Resource Group for our resources to reside in. We'll use an Azure CLI command to do that. 

```bash
az group create -l westus -n vnet-tutorial --tags Owner=Sarah Purpose=Tutorial

```

Now to deploy our template: 

```bash
az deployment group create --resource-group vnet-tutorial --template-file vnet.bicep

```

In the command, we are saying deploy to our **vnet-tutorial** resource group and we're telling the command to deploy our **vnet.bicep** template. 

The command will start to run and after a few minute you should have your Virtual Network deployed. 

![Deployed resource within Azure](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2022/03/deployedresource.png)

Deployed resource within Azure

## Is Azure Bicep production ready?

Yes, as of [version 0.3 Azure Bicep](https://github.com/Azure/bicep/releases?ref=techielass.com) is production ready. It is supported by Microsoft Support Plans and Bicep has 100% parity with what can be accomplished by ARM template. 

I hope that helps you get started and explains a bit more about Azure Bicep. Do check out the [Microsoft Learn module](https://docs.microsoft.com/learn/paths/fundamentals-bicep/?WT.mc%5Fid=AZ-MVP-5004737&ref=techielass.com) or my video explaining why Azure Bicep has become so popular.