Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 15, 2022 07:54 am GMT

Introduction to Azure Bicep

Azure Bicep

Azure Bicep is a new Domain-Specific Language (DSL) for declaratively deploying Azure resources. Bicep is not a general purpose programming language but a transparent abstraction for Azure Resource Manager (ARM) Templates. This ensures that the properties that are valid in ARM templates are valid in Bicep as well.

Benefits of Bicep

Bicep provides the following advantages:

  1. Support for all resource types and API versions
  2. Simple syntax
  3. Authoring experience
  4. Repeatable results
  5. Orchestration
  6. Modularity
  7. Integration with Azure services
  8. Preview changes
  9. No state or state files to manage
  10. No cost and open source

Why Bicep?

ARM templates are JSON documents that offer a declarative way of defining our Azure infrastructure and configuration. ARM template language offers built-in functions and other language constructs such as loops and that help us to create more dynamic infrastructure definitions.

However, the JSON syntax for ARM templates makes the documents quite verbose and restricts the extensibility since we have to play what is supported within JSON data representation.

As the complexity of the infrastructure grows, our ARM template becomes almost unreadable and difficult to maintain as well. There are alternatives to ARM template deployment. Especially, HashiCorp Terraform or Pulumi SDK. These tools do not use ARM templates but provide alternate ways to define our infrastructure as code.

The following examples show the difference between a Bicep file and the equivalent JSON template. Both examples deploy a storage account.

param storageAccountName stringparam accessTier string = 'Hot'param location string = 'WestUS2'resource sa 'Microsoft.Storage/storageAccounts@2019-06-01' = {  name: storageAccountName  location: location  sku: {    name: 'Standard_LRS'  }  kind: 'StorageV2'  properties: {    accessTier: accessTier  }}

The 26 lines in the above example is what you need to create a reusable Bicep file that can generate ARM template to provision an Azure storage account. This, when compiled, produces the following ARM template.

{  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",  "contentVersion": "1.0.0.0",  "parameters": {    "storageAccountName": {      "type": "string"    },    "accessTier": {      "type": "string",      "defaultValue": "Hot"    },    "location": {      "type": "string",      "defaultValue": "WestUS2"    }  },  "functions": [],  "resources": [    {      "type": "Microsoft.Storage/storageAccounts",      "apiVersion": "2019-06-01",      "name": "[parameters('storageAccountName')]",      "location": "[parameters('location')]",      "sku": {        "name": "Standard_LRS"      },      "kind": "StorageV2",      "properties": {        "accessTier": "Hot"      }    }  ],  "metadata": {    "_generator": {      "name": "bicep",      "version": "0.3.126.58533",      "templateHash": "6796585337478950038"    }  }}

The generated template is almost twice the size of the Bicep file. This ARM template can be deployed by supplying the necessary parameter values as another JSON or at the command line when using Azure CLI or Azure PowerShell.

This is a example where it shows the flexibility that we are having with this language of its own to generate the ARM templates. Bicep provides not just the constructs of a typical programming language but also a way to compose our Azure infrastructure definitions as smaller reusable modules.

Thanks for reading my article till end. I hope you learned something special today. If you enjoyed this article then please share to your friends and if you have suggestions or thoughts to share with me then please write in the comment box.


Original Link: https://dev.to/makendrang/introduction-to-azure-bicep-5je

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To