Azure Bicep: Deployment and Infrastructure as Code

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, resources, variables, outputs, and modules. Today, we’re going to take another step forward. We’ll explore one of the key components of Azure Bicep - Deployment. 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.
    # Log in 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 Deployment

Deployment in Azure Bicep is the process of deploying your Bicep files to Azure. You can deploy a Bicep file using the az deployment group create command in Azure CLI.

Here’s an example of a Bicep file that can be deployed.

param storageAccountName string = 'mystorageaccount'

var location = 'westus'

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

output storageAccountId string = storageAccount.id

You can deploy this Bicep file using the following command.

# Deploy the Bicep file

az deployment group create --resource-group myResourceGroup --template-file ./main.bicep

In this example, the az deployment group create command is used to deploy the Bicep file to the myResourceGroup resource group.

Conclusion

Well done! You’ve just learned how to deploy Azure Bicep files. Deployment is a powerful feature that allows you to deploy your infrastructure as code to Azure. In our next session, we’ll explore best practices in Azure Bicep. So, stay tuned and keep learning.


Similar Articles