Deploying workloads and resources to Microsoft Azure using Bicep can save time and effort; however, when deploying multiple resources, it is handy to use a parameter file to store all the parameters.

This blog post will show how to use a parameter file with Bicep and call it using Azure CLI.

In our case, we are going to create a storage account using a Bicep template and use a parameter file that will store the name of the storage account (storageaccountname)

Parameters File

A parameter file in Bicep is a JSON file containing parameters with defined values. The file can contain multiple parameters type (string, int, et. c) and their values.

In this example, I have named the parameter file parameters.json

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "storageaccountname": {
        "value": "ntweeklyc0002"
      }
    } 
}    

Bicep Template

Below you can see our Bicep template file. In line 1, I have defined the storageaccountname parameter. It is important to note that the parameter name in the template file needs to match the parameter name in the parameter file.

param storageaccountname string
resource storageAccount 'Microsoft.Storage/storageAccounts@2019-06-01' = {
  name: storageaccountname
  location: resourceGroup().location
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
  properties: {
    accessTier: 'Hot'
  }
}

Azure CLI Deploy code

The last step in the deployment process of a template file is to deploy it using Azure CLI. Below I’m deploying the template using the following switch –parameters @parameters.json

az deployment group create  --name  vars  --template-file 2.2.storage_account.bicep  --parameters @parameters.json --resource-group biceplab

Processing…
Success! You're on the list.

Posted

in

,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.