In this lab, I dove into the fundamentals of Infrastructure as Code (IaC) using Azure Resource Manager (ARM) templates. The goal was simple but powerful: write, deploy, and modify an ARM template using VS Code and the Azure CLI β all within my own subscription.
πΌ Scenario
As a cloud administrator, I needed to automate the deployment of infrastructure. In this lab, I:
- β Created and deployed a blank ARM template
- β Modified it to deploy a Storage Account
- β Practiced real-world deployment from Visual Studio Code
- β Troubleshot issues on macOS (and learned a ton!)
π οΈ Prerequisites I Used
To complete this lab, I had:
- β My Azure subscription
- β Visual Studio Code
- β The Azure CLI (eventually π )
- β The ARM Tools extension installed in VS Code
π§ͺ Task 1: Create and Deploy a Blank ARM Template
πΉ Step 1: Create the Template in VS Code
I opened VS Code and created a new file named azuredeploy.json. Then I typed arm! and selected the ARM Template snippet. That gave me this basic template:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"functions": [],
"variables": {},
"resources": [],
"outputs": {}
}
π‘ VS Code popped up a message about a missing parameters file β but no worries, I ignored it for now since I wasnβt using parameters yet.
πΉ Step 2: Fixing Azure CLI on macOS π
I hit a snag when trying to run az login:
bash: az: command not found
π§° How I Fixed It:
- β Installed Homebrew first (since I didnβt have it):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- β Installed Azure CLI:
brew update && brew install azure-cli
- β Verified the installation:
az version
- β Fixed the PATH in both Zsh and Bash profiles:
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zprofile
source ~/.zprofile
Now az was working!
πΉ Step 3: Log In and Create Resource Group
With the CLI working, I logged into Azure:
az login
I selected my subscription (my first ever subscription) and created a resource group:
az group create --name RG1 --location "East US"
πΉ Step 4: Deploy the Blank Template
I deployed the blank ARM template like this:
templateFile="azuredeploy.json"
today=$(date +"%d-%b-%Y")
DeploymentName="blanktemplate-$today"
az deployment group create \
--resource-group RG1 \
--name $DeploymentName \
--template-file $templateFile
β I went to the Azure Portal > Resource Groups > RG1 > Deployments β and saw the blank deployment succeed!
π§ͺ Task 2: Add a Storage Account to the Template
πΉ Step 1: Insert a Storage Resource
Inside the "resources": [] section of azuredeploy.json, I typed storage and selected the arm-storage snippet. It gave me:
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2021-04-01",
"name": "[concat('mystorage', uniqueString(resourceGroup().id))]",
"location": "[resourceGroup().location]",
"sku": {
"name": "Standard_LRS",
"tier": "Standard"
},
"kind": "StorageV2",
"properties": {}
}
This snippet auto-generates a unique storage account name based on the resource group ID β a great trick for avoiding name collisions.
πΉ Step 2: Redeploy the Updated Template
With the storage account resource added, I saved the file and redeployed:
templateFile="azuredeploy.json"
today=$(date +"%d-%b-%Y")
DeploymentName="addstorage-$today"
az deployment group create \
--resource-group RG1 \
--name $DeploymentName \
--template-file $templateFile
β Back in the portal, I saw:
- A second deployment listed
- A new Storage Account successfully created!
π§ What I Learned
This lab was a perfect intro to ARM templates and IaC. I learned how to:
- πΉ Write and structure a basic ARM template
- πΉ Deploy infrastructure using the Azure CLI
- πΉ Modify the template to include real Azure resources
- πΉ Troubleshoot CLI issues on macOS like a pro π
π§Ή Bonus Tip: Cleanup Resources
If you're practicing in your own subscription, you can remove everything quickly with:
az group delete --name RG1
β Key Takeaways
- ARM templates give you full control over Azure resource deployments
- VS Code + ARM Tools extension = IaC superpowers πͺ
- Even a simple JSON template can deploy real cloud infrastructure
- The Azure CLI is essential β and fixing it taught me more than the lab itself!
On to the next lab! π»π₯
Top comments (0)