Microsoft Bicep
for IaC
Agenda
-
Infrastructure as Code
-
ARM Templates
-
Bicep
-
Demo
Infrastrucutre as Code
(IaC)
1. First there were snowflakes...
2. Then there was automation...
3. Finally there was code...
ARM Templates
-
Azure Resource Manager Templates
-
JSON Syntax - and Schemas
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.16.2.56959",
"templateHash": "1346177644236912037"
}
},
"parameters": {
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Premium_LRS",
"Premium_ZRS",
"Standard_GRS",
"Standard_GZRS",
"Standard_LRS",
"Standard_RAGRS",
"Standard_RAGZRS",
"Standard_ZRS"
],
"metadata": {
"description": "Storage Account type"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "The storage account location."
}
},
"storageAccountName": {
"type": "string",
"defaultValue": "[format('store{0}', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "The name of the storage account"
}
}
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2022-09-01",
"name": "[parameters('storageAccountName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('storageAccountType')]"
},
"kind": "StorageV2",
"properties": {}
}
],
"outputs": {
"storageAccountName": {
"type": "string",
"value": "[parameters('storageAccountName')]"
},
"storageAccountId": {
"type": "string",
"value": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
}
}
}
Bicep
-
Domain Specific Language (DSL)
-
Concise syntax, reliable type safety, and support for code reuse.
-
Support for all resource types and API versions
@description('Storage Account type')
@allowed([
'Premium_LRS'
'Premium_ZRS'
'Standard_GRS'
'Standard_GZRS'
'Standard_LRS'
'Standard_RAGRS'
'Standard_RAGZRS'
'Standard_ZRS'
])
param storageAccountType string = 'Standard_LRS'
@description('The storage account location.')
param location string = resourceGroup().location
@description('The name of the storage account')
param storageAccountName string = 'store${uniqueString(resourceGroup().id)}'
resource sa 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: storageAccountName
location: location
sku: {
name: storageAccountType
}
kind: 'StorageV2'
properties: {}
}
output storageAccountName string = storageAccountName
output storageAccountId string = sa.id
Demo
Links
Microsoft Bicep for IaC
By Kjell Otto
Microsoft Bicep for IaC
This is my presentation accompanying the small presentation of how to setup Azure DevOps for Bicep Infrastructure as Code deployment toolchain.
- 179