AzInsider
Glossary GitHub GitHub Issues Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Last updated: 02 May 2024

Fundamentals


Azure Bicep streamlines the deployment of Azure resources through its declarative syntax, which outlines the desired state of resources without specifying the step-by-step process to achieve it. Here’s a breakdown of its main concepts with samples:

  1. Declarative Syntax: Bicep simplifies Azure resource deployment with its clear and concise syntax. For example:
resource myStorageAccount 'Microsoft.Storage/storageAccounts@2021-04-01' = {
  name: 'mystorageaccount'
  location: 'eastus'
  sku: {
    name: 'Standard_LRS'
  }
}
  1. Resource Declaration: Resources are defined using resource blocks, specifying type, name, and properties. Here’s a sample:
resource myAppService 'Microsoft.Web/sites@2021-01-01' = {
  name: 'myappservice'
  location: 'westus'
  properties: {
    serverFarmId: myAppServicePlan.id
  }
}
  1. Expressions: Bicep supports expressions for dynamic value generation. For example:
var storageAccountName = 'mystorageaccount'
resource myStorageAccount 'Microsoft.Storage/storageAccounts@2021-04-01' = {
  name: storageAccountName
  // other properties
}
  1. Parameters and Variables: Parameters allow runtime customization, while variables enable value reuse. Example:
param location string = 'westus'
var resourceGroupName = 'myResourceGroup'
  1. Modules: Modularization is achieved through modules, promoting code reuse. Sample usage:
module mySubnet 'subnets.bicep' = {
  name: 'subnetModule'
  params: {
    subnetName: 'mySubnet'
    addressPrefix: '10.0.0.0/24'
  }
}
  1. Output Declaration: Outputs expose important values post-deployment. Example:
output storageAccountConnectionString string = myStorageAccount.properties.primaryEndpoints.blob
  1. Conditions and Loops: Bicep supports conditional logic and loops for dynamic deployments. Sample usage:
for i in range(5) {
  resource myVMs[i] 'Microsoft.Compute/virtualMachines@2021-04-01' = {
    name: 'myVM-${i}'
    // other properties
  }
}

In summary, Azure Bicep offers a straightforward approach to deploying Azure resources through its intuitive syntax, expressions, parameters, modules, outputs, and support for conditions and loops, enhancing the manageability and scalability of infrastructure deployments.