Unraveling Azure Bicep Resources

Introduction

Hello everyone! We’ve been on an exciting journey exploring Azure Bicep. We’ve seen what it is, and how it compares to ARM templates, set up our environment, dived into its syntax, and explored parameters. Today, we’re going to take another step forward. We’ll explore one of the key components of Azure Bicep - Resources. So, let’s get started.

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 Resources

Resources in Azure Bicep are the Azure resources that you want to deploy. They are defined using the resource keyword. Here’s an example,

param storageAccountName string = 'mystorageaccount'

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

In this example, storageAccount is a resource of type Microsoft.Storage/storageAccounts@2021-04-01. The name property of the resource is set to the storage account name parameter, the location property is set to the location of the resource group, and the SKU and kind properties are set to ‘Standard_LRS’ and ‘StorageV2’, respectively.

Conclusion

Well done! You’ve just learned how to use resources in Azure Bicep. Resources are a powerful feature that allows you to define and deploy Azure resources. In our next session, we’ll explore variables in Azure Bicep. So, stay tuned and keep learning!