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)