az bicep install40 minutes
This lab uses Azure CLI — ensure az is installed and authenticated to your Azure subscription before proceeding.
az group create --name rg-az104-lab07 --location eastusSave your Bicep file in a directory with no spaces in the path to avoid CLI parsing issues.
Create main.bicep:
@description('Name prefix for resources')
param namePrefix string = 'az104lab07'
@allowed(['Standard<em>LRS', 'Standard</em>GRS'])
param storageSku string = 'Standard<em>LRS'
var storageAccountName = toLower('${namePrefix}${uniqueString(resourceGroup().id)}')
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = {
name: storageAccountName
location: resourceGroup().location
sku: {
name: storageSku
}
kind: 'StorageV2'
properties: {
minimumTlsVersion: 'TLS1</em>2'
allowBlobPublicAccess: false
}
}
resource vnet 'Microsoft.Network/virtualNetworks@2023-09-01' = {
name: '${namePrefix}-vnet'
location: resourceGroup().location
properties: {
addressSpace: {
addressPrefixes: ['10.20.0.0/16']
}
subnets: [
{
name: 'default'
properties: {
addressPrefix: '10.20.0.0/24'
}
}
]
}
}
output storageAccountName string = storageAccount.name
output vnetId string = vnet.id
Always run what-if before deploying to production. It shows exactly what changes will occur without modifying any resources.
az deployment group what-if \--resource-group rg-az104-lab07 \
--template-file main.bicep
Review the predicted Create operations before applying.
az deployment group create \--resource-group rg-az104-lab07 \
--template-file main.bicep \
--parameters storageSku=Standard<em>LRS \
--name lab07-deployment
az deployment group show -g rg-az104-lab07 -n lab07-deployment --query properties.outputs
Decompile to compare:
az bicep decompile --file main.json # if you have JSON, converts to bicep<h1>or build bicep -> json:</h1>
az bicep build --file main.bicep # produces main.json
Open main.json and identify: $schema, contentVersion, parameters,
variables, resources, outputs — map each to its Bicep equivalent.
Complete mode deletes resources NOT in your template. Never use it in production unless you fully understand the consequences.
Modify storageSku to StandardGRS and redeploy with Incremental mode (default):
az deployment group create -g rg-az104-lab07 --template-file main.bicep \--parameters storageSku=Standard_GRS --mode Incremental
Discuss (no need to execute): Complete mode would delete resources in the
RG that are not in the template — dangerous, used carefully.
az deployment group list -g rg-az104-lab07 -o tableaz deployment operation group list -g rg-az104-lab07 -n lab07-deployment -o table
what-if output reviewed before deployingstorageAccountName, vnetId) returned correctlyaz group delete --name rg-az104-lab07 --yes --no-waitwhat-if shows Create/Modify/Delete/NoChange without applying changes — use it before production deployments.uniqueString() is commonly used to generate globally-unique names deterministically from the resource group ID.