DEV Community

1suleyman
1suleyman

Posted on

๐Ÿš€ Exercise 01: Building Azure Infrastructure as Code (And Fixing My Subscription Along the Way)

Hey folks ๐Ÿ‘‹

Just wrapped up a hands-on exercise in Azure using Bicep โ€” Azureโ€™s simpler, cleaner way to define infrastructure as code. If youโ€™re like me and enjoy seeing your resources magically appear in the Azure portal (but without all the clicking around), youโ€™ll probably enjoy this one.

Hereโ€™s how it went down โ€” including what worked, what broke, and what I learned about quotas (and subscriptions that scream โ€œplease upgrade meโ€).


๐ŸŽฏ What I Set Out To Do

In this exercise, I wanted to:

  • Define a Storage Account, App Service Plan, and Web App using Bicep
  • Deploy it through Azure CLI
  • Use my own Azure subscription (yes, even on the free tier)
  • Learn how to debug when things go sideways ๐Ÿ™ƒ

๐Ÿงช Step 1: Define the Storage Account in Bicep

I cracked open VS Code and created a file called main.bicep. Hereโ€™s the starter code:

resource storageAccount 'Microsoft.Storage/storageAccounts@2023-05-01' = {
  name: 'toylaunchstoragebob' // ๐Ÿ” Must be globally unique, lowercase, no special chars
  location: 'westus'
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
  properties: {
    accessTier: 'Hot'
  }
}
Enter fullscreen mode Exit fullscreen mode

โœ… Tip: Storage account names must be globally unique. I used 'toylaunchstoragebob' โ€” feel free to copy or change it to match your vibe.


๐Ÿ› ๏ธ Troubleshooting az login on macOS with PowerShell

I hit a bump when trying to run az login in PowerShell on my Mac. Turns out, PowerShell couldnโ€™t find the Azure CLI path. If thatโ€™s you too, hereโ€™s how I fixed it:

  1. Run which az in Zsh/Bash โ†’ it gave me /opt/homebrew/bin/az
  2. Open your PowerShell profile: code $PROFILE
  3. Add this to the bottom:
   $env:PATH += ":/opt/homebrew/bin"
Enter fullscreen mode Exit fullscreen mode
  1. Restart PowerShell. Now az login works!

๐Ÿง‘โ€๐Ÿ’ป Log In and Set Up Your Resource Group

az login
az account set --subscription "Your Subscription Name"
az group create --name BicepRG --location westus
Enter fullscreen mode Exit fullscreen mode

๐Ÿš€ Deploy the Storage Account

az deployment group create \
  --resource-group BicepRG \
  --template-file main.bicep \
  --name deploy-storage
Enter fullscreen mode Exit fullscreen mode

โœ… Head over to Azure Portal โ†’ Resource Groups โ†’ BicepRG

Boom. One shiny new Storage Account ๐ŸŽ‰


๐Ÿงช Step 2: Add an App Service Plan + Web App

I expanded my main.bicep file to look like this:

resource appServicePlan 'Microsoft.Web/serverfarms@2024-04-01' = {
  name: 'toylaunchappserviceplanbob'
  location: 'westus'
  sku: {
    name: 'F1'
  }
}

resource appServiceApp 'Microsoft.Web/sites@2024-04-01' = {
  name: 'toylaunchappbob'
  location: 'westus'
  properties: {
    serverFarmId: appServicePlan.id
    httpsOnly: true
  }
}
Enter fullscreen mode Exit fullscreen mode

Then I ran the deployment again:

az deployment group create \
  --resource-group BicepRG \
  --template-file main.bicep \
  --name deploy-app
Enter fullscreen mode Exit fullscreen mode

๐Ÿ˜ฉ And Then Azure Was Like: โ€œNah Broโ€

I got this error:

The template deployment is not valid...
"SubscriptionIsOverQuotaForSku": "This region has quota of 0 instances for your subscription..."
Enter fullscreen mode Exit fullscreen mode

Translation? My free-tier subscription didnโ€™t have enough quota in East US to deploy App Services.

โœ… Fix: I switched everything to westus and re-deployed.


โœ… Final Results: Check the Portal

In the Azure Portal โ†’ Resource Groups โ†’ BicepRG, I saw:

  • ๐Ÿ—„๏ธ A Storage Account
  • ๐Ÿงฑ An App Service Plan
  • ๐ŸŒ A Web App

Itโ€™s all there. And it was all built from a single Bicep template.


๐Ÿ“ฆ What I Learned

Task What I Did
๐Ÿ’พ Create Bicep Template Defined 3 Azure resources using clean Bicep syntax
๐Ÿ’ป Use Azure CLI Deployed using az deployment group create
๐Ÿค Work in My Own Subscription Hit some quota errors, but learned how to troubleshoot
๐Ÿ” Verified the Setup Used Azure CLI and Portal to double-check everything

๐Ÿค Letโ€™s Connect

If youโ€™re learning Azure and Infrastructure as Code too, Iโ€™d love to connect with others on the same journey.

Drop me a message on LinkedIn and just say hi!

Top comments (0)