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)