Azure Resource deployment with Bicep
Shamali Weerasinghe
Associate Tech Lead @ TIQRI | AI/BI Practice Lead @ TIQRI | Data Engineer | AI Enthusiast | BI Specialist | Data Analyst | Power BI Developer
Bicep
In order to deploy Azure resources among approaches as through the Azure portal and through ARM templates, Pulumi, and many other the approach through Bicep files can be considered as one of the convenient as well as efficient approach.
Bicep is the simplest approach when it comes to deploy multiple resources to multiple clients or onto multiple resource groups.
Bicep is a domain-specific language (DSL), which uses declarative syntax in order to deploy Azure resources.
Bicep syntax reduces the complexity unlike in the JSON format in the ARM templates. So in that way Bicep can be considered as the abstract version of the ARM templates with reduced complexity but not with reduced capabilities. Ultimately during the deployment, the Bicep file will be converted into an ARM template by the Bicep CLI, leaving less amount of work to the Developer.
az bicep decompile -f test.json
The following bicep code provisions a new storage account.
The name of the new storage account (stgActName), location, sku (stgActSku) can be defined in the bicep file itself or a separate parameter file (JSON) can be used.
In the following parameters are defined in the bicep file itself.
In the following a separate parameter file is created and the parameters are declared.
Bicep Module usage
Modules can be used to organize the resource deployments. A module is simply another bicep file which refers other bicep files. With the use of modules, it enhances code reuse as the same resource deployment bicep file can be called by many other deployments via modules and also reduces the complexity as it encapsulates complex details.
The given below code deploys a storage account and a hosting plan by calling the StorageTemplate.bicep.
Deployment of Azure Bicep files
Bicep files can be deployed in multiple ways as either manually or automatedly.
Deploying a Bicep file using the Azure CLI command:
New-AzResourceGroupDeployment -Name NameOfTheAzureResource -TemplateFile C:bicepFilePath.bicep
New-AzResourceGroupDeployment -Name NameOfTheAzureResource -TemplateFile C:yamlFilePath.bicep
领英推荐
?YAML file for Bicep deployment
(YAML is used for writing configuration files and it is a data serialization language)
The following is an example for yaml file.
The above yaml code validates and deploys the resource (storage account) defined in the bicep (StorageTemplate.bicep)
If the parameters are defined in a separate parameter.json file the file locations also should be provided after the bicep file location
Eg: --parameters @Infrastructure/Parameters/fappmain.parameters.json\
The *AzureSubscription and the Resource Group names can be passed as either a separate variable or as a variable group.
The AzureSubscription and the Resource Group names can be passed as a variable group.
Azure DevOps Variable Group
Azure Service Connection
*AzureSubscription in the yaml file is simply the Connection between Azure DevOps pipelines and the external remote azure services.
Inorder to create a new Service Connection:
1. Log into the Azure DevOps Project
2. Project settings -> Service Connections -> New Service Connection
3. Select Azure Resource Manager and Service Principal (automatic)
4. Provide the Subscription and Resource Group details.
?Afterwards the developed YAML files can be deployed with the use of scheduled pipelines.
Likewise at a time with a requirement to provision multiple resources to multiple environments, Bicep can be used to perform the tedious steps and to increase the efficiency with just a little number of codes.?