Introduction
In our previous articles, we introduced Azure Bicep and compared it with ARM templates. Now that we have a good understanding of what Azure Bicep is and why it’s a compelling alternative to ARM templates, it’s time to get our hands dirty. In this article, we will set up our environment for Azure Bicep and create our first Azure Bicep file.
Setting up the Environment
Before we start writing Azure Bicep files, we need to set up our environment. Here are the steps.
- Install Azure CLI: Azure CLI is a command-line tool that you can use to manage Azure resources. You can download it from the official Azure website here.
# Check your installed version
az --version
- Install Bicep CLI: Bicep CLI is a command-line tool that you can use to work with Bicep files. You can install it using Azure CLI.
# Install Bicep CLI
az bicep install
# Check your installed version
az bicep version
- Install Visual Studio Code and Bicep extension: Visual Studio Code is a popular code editor, and the Bicep extension provides features like autocompletion, code navigation, and live linting.
You can install VS Code from here.
Once you have installed VS Code, use the below command to install the Bicep Extension.
# Open Visual Studio Code and install Bicep extension
code --install-extension ms-azuretools.vscode-bicep
Logging in to Azure and Setting the Subscription
Before deploying the Bicep file, we need to log in to Azure and set the subscription. Here are the steps.
- Log in to Azure: Use the az login command to log in to Azure.
# Log in to Azure
az login
- Set the subscription: Use the az account set command to set the subscription.
# Set the subscription
az account set --subscription "mySubscription"
Creating your first Azure bicep file
Now that our environment is set up, let’s create our first Azure Bicep file. We will create a simple Bicep file that deploys a storage account.
- Create a new Bicep file: In Visual Studio Code, create a new file with a .bicep extension.
- Define a storage account resource: In the Bicep file, define a storage account resource as follows.
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-04-01' = {
name: 'mystorageaccount'
location: resourceGroup().location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
}
- Deploy the Bicep file: You can deploy the Bicep file using Azure CLI.
# Deploy the Bicep file
az deployment group create --resource-group myResourceGroup --template-file ./main.bicep
Conclusion
Congratulations! You have set up your environment for Azure Bicep and created your first Azure Bicep file. In the next article, we will dive deeper into the syntax of Azure Bicep. Stay tuned