Azure Bicep CLI and functions cheet sheet

Overall Azure bicep is the best repalcement for AWS CDK currently available (2023) and the recommended way to express infrastructure-as-code in the aure universe.

Bicep CLI

All command require azure CLI and PowerShell 7.x.x

Select subscription by name / set context

$context = Get-AzSubscription -SubscriptionName '<name of the subscription>'
Set-AzContext $context

Set default

Set-AzDefault -ResourceGroupName <resource-group-name>

Run bicep deployment

New-AzResourceGroupDeployment -TemplateFile main.bicep

Read resource group

Get-AzResourceGroupDeployment -ResourceGroupName <resource-group-name> | Format-Table

List resource groups

Get-AzResourceGroup

Bicep functions

Random unique name uniqueString

param fooUniceName string = 'fooo${uniqueString('constant-seed-value')}'

Create resource group with bicep

targetScope = 'subscription'
param location string = deployment().location

resource rg 'Microsoft.Resources/resourceGroups@2022-09-01' = {
    name: 'myName'
    location: location
}
az deployment create --location westeurope  --template-file .\main.bicep

Links

Paul Sterl has written 52 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>