Dive into Azure Bicep Syntax & Basics

Introduction

Hello everyone! In our previous sessions, we’ve been on a journey exploring Azure Bicep. We’ve seen what it is and how it compares to ARM templates, and we even got our hands dirty by setting up our environment and creating our first Azure Bicep file. Today, we’re going to dive a bit deeper. We’ll explore the syntax of Azure Bicep, which I believe you’ll find quite intuitive and easy to grasp.

Logging in to Azure

Before we start, let’s ensure we’re logged into Azure. Here’s how you can do it.

  1. Open your terminal or command prompt: You can use any terminal or command prompt that you’re comfortable with.
  2. Log in to Azure: Use the az login command to log in to Azure.
    # Login to Azure
    
    az login
    
  3. Set your subscription: Use the az account set command to set your subscription.
    # Set your subscription
    az account set --subscription "YourSubscriptionName"
    

Azure Bicep Syntax

Now that we’re logged in, let’s get to the fun part - Azure Bicep syntax. Here are some key components:

Parameters

Parameters are like the inputs to your Bicep file. You can define a parameter using the param keyword.

param storageAccountName string = 'mystorageaccount'

Resources

Resources are the Azure resources that you want to deploy. You can define a resource using the resource keyword.

resource storageAccount 'Microsoft.Storage/storageAccounts@2021-04-01' = {
  name: storageAccountName
  location: resourceGroup().location
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
}

Variables

Variables are like the constants in your Bicep file. You can define a variable using the var keyword.

var location = 'westus'

Outputs

Outputs are the results that are returned after deployment. You can define an output using the output keyword.

output storageAccountId string = storageAccount.id

Conclusion

Well done! You’ve just learned the syntax of Azure Bicep and how to define parameters, resources, variables, and outputs. In our next session, we’ll explore parameters in Azure Bicep in more detail. So, stay tuned and keep learning!