DEV Community

1suleyman
1suleyman

Posted on

Exercise 01: Deploy an ARM Template Using Azure CLI and VS Code

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": {}
}
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ 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
Enter fullscreen mode Exit fullscreen mode

🧰 How I Fixed It:

  1. βœ… Installed Homebrew first (since I didn’t have it):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode
  1. βœ… Installed Azure CLI:
brew update && brew install azure-cli
Enter fullscreen mode Exit fullscreen mode
  1. βœ… Verified the installation:
az version
Enter fullscreen mode Exit fullscreen mode
  1. βœ… Fixed the PATH in both Zsh and Bash profiles:
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zprofile
source ~/.zprofile
Enter fullscreen mode Exit fullscreen mode

Now az was working!


πŸ”Ή Step 3: Log In and Create Resource Group

With the CLI working, I logged into Azure:

az login
Enter fullscreen mode Exit fullscreen mode

I selected my subscription (my first ever subscription) and created a resource group:

az group create --name RG1 --location "East US"
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή 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
Enter fullscreen mode Exit fullscreen mode

βœ… 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": {}
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

βœ… 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
Enter fullscreen mode Exit fullscreen mode

βœ… 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)