🧰 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. 🚀