π§° Tools I Used:
- Visual Studio Code (with the Bicep extension)
- Azure CLI + Bicep CLI
- An active Azure subscription
π― Goal:
In this exercise, I focused on making my Bicep template more reusable and environment-aware. Hereβs what I accomplished:
β
Accepted parameters like location and environment type
β
Used variables to dynamically choose SKUs
β
Generated unique names for my storage account and web app
β
Deployed it all with a single CLI command
π οΈ Step 1: Add Parameters and Variables
Inside main.bicep
, I added parameters to keep things flexible β so I wouldnβt hardcode values like region or service names.
param location string = 'westus'
param storageAccountName string = 'toylaunch${uniqueString(resourceGroup().id)}'
param appServiceAppName string = 'toylaunchapp${uniqueString(resourceGroup().id)}'
@allowed([
'nonprod'
'prod'
])
param environmentType string
var appServicePlanName = 'toy-product-launch-plan'
var storageAccountSkuName = (environmentType == 'prod') ? 'Standard_GRS' : 'Standard_LRS'
var appServicePlanSkuName = (environmentType == 'prod') ? 'P2v3' : 'F1'
β‘οΈ This setup means I can choose between prod and nonprod, and the template will auto-select the right SKUs.
ποΈ Step 2: Update Resources to Use Parameters
Here's how I wired those parameters and variables into the resource definitions:
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-05-01' = {
name: storageAccountName
location: location
sku: {
name: storageAccountSkuName
}
kind: 'StorageV2'
properties: {
accessTier: 'Hot'
}
}
resource appServicePlan 'Microsoft.Web/serverfarms@2024-04-01' = {
name: appServicePlanName
location: location
sku: {
name: appServicePlanSkuName
}
}
resource appServiceApp 'Microsoft.Web/sites@2024-04-01' = {
name: appServiceAppName
location: location
properties: {
serverFarmId: appServicePlan.id
httpsOnly: true
}
}
π Step 3: Deploy!
Logged in:
az login
az account set --subscription "My Subscription"
Deployed with:
az deployment group create \
--resource-group BicepRG \
--name deploy-bicep-env \
--template-file main.bicep \
--parameters environmentType=nonprod
π
First, I forgot to create the resource groupβrookie mistake. Fixed it with:
az group create \
--name BicepRG \
--location westus
β Step 4: Check the Azure Portal
Boom π₯ β after deploying, I jumped into the Azure Portal and opened up the BicepRG resource group. There it was:
- A Storage Account
- An App Service Plan
- A Web App
- All with the correct SKUs for nonprod:
Standard_LRS + F1
π Bonus: Try a Production Deployment
Changed just one value in the CLI:
az deployment group create \
--resource-group BicepRG \
--name deploy-bicep-prod \
--template-file main.bicep \
--parameters environmentType=prod
β That deployed a Standard_GRS storage account and a P2v3 App Service Plan β super clean.
π¦ Recap
Task | What I Learned/Did |
---|---|
Parameters | Accepted inputs like location and environment |
Variables | Used logic to change SKUs based on environment |
Dynamic naming | Used uniqueString() to avoid name clashes |
Deployment | Used az deployment group create for both envs |
Verified | Checked everything in the Portal π |
π¬ Learning Bicep? Or working on Azure infra too?
Letβs connect on LinkedIn β drop me a message and say hi! Always happy to chat with other folks on the same path. π
Top comments (0)