What is Bicep?
Tags: azure, dsl, bicep, language
Published: 2022-05-15 07:51:04



## **Azure Bicep**


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





## **Benefits of Bicep**

Bicep presents the following advantages:


1. Support for all useful 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 kingdom documents to manage
10. No price and open source


## **Why Bicep?**

ARM templates are JSON documents that provide 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 assist us to create greater dynamic infrastructure definitions.

However, the JSON syntax for ARM templates makes the files quite verbose and restricts the extensibility due to the fact we have to play what is supported within JSON statistics representation.

As the complexity of the infrastructure grows, our ARM template turns into nearly unreadable and difficult to maintain as well. There are picks to ARM template deployment. Especially, HashiCorp Terraform or Pulumi SDK. These tools do not use ARM templates but grant alternate ways to outline our infrastructure as code.

The `complexity of the infrastructure` makes it difficult to maintain the template. There are other ways to deploy the template. Especially, the **Pulumi SDK** or the **HashiCorp Terraform**. These tools don't use templates, but instead give alternate ways to define our infrastructure as code.

There is a difference between a Bicep file and an equivalent template. There are two examples that deploy a storage account.

The following examples exhibit the distinction between a Bicep file and the equivalent JSON template. Both examples set up a storage account.


```
param storageAccountName string
param 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 traces in the above instance 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 nearly twice the measurement of the Bicep file. This ARM template can be deployed through providing the critical parameter values as another JSON or at the command line when the use of Azure CLI or Azure PowerShell.

This is a instance the place it suggests the flexibility that we are having with this language of its own to generate the ARM templates. Bicep presents now not just the constructs of a traditional programming language but also a way to compose our Azure infrastructure definitions as smaller reusable modules.




Gratitude for perusing my article till end.I hope you realized something unique today. If you enjoyed this article then please share to your buddies and if you have suggestions or thoughts to share with me then please write in the comment box.