0
0
Azurecloud~30 mins

Scripting with variables and loops in Azure - Mini Project: Build & Apply

Choose your learning style9 modes available
Scripting with variables and loops
📖 Scenario: You are managing a small Azure environment. You want to automate the creation of multiple storage accounts with similar settings using a script. This will save time and reduce manual errors.
🎯 Goal: Create an Azure CLI script that uses variables and a loop to create three storage accounts with specific names and locations.
📋 What You'll Learn
Use a variable to store the base name for storage accounts
Use a variable to store the location for all storage accounts
Use a loop to create three storage accounts with names based on the base name and an index
Use the Azure CLI az storage account create command with the correct parameters
💡 Why This Matters
🌍 Real World
Automating repetitive cloud resource creation saves time and reduces mistakes in managing Azure environments.
💼 Career
Cloud engineers and DevOps professionals often write scripts like this to deploy and manage resources efficiently.
Progress0 / 4 steps
1
Set up base variables
Create two variables: baseName set to mystorage and location set to eastus.
Azure
Need a hint?

Use simple variable assignment in bash style: variable=value.

2
Add a loop counter
Create a variable called count and set it to 3 to represent how many storage accounts to create.
Azure
Need a hint?

Use the same variable assignment style as before.

3
Write the loop to create storage accounts
Write a for loop using i from 1 to $count. Inside the loop, use az storage account create with --name set to ${baseName}${i} and --location set to $location. Use --resource-group myResourceGroup and --sku Standard_LRS as fixed parameters.
Azure
Need a hint?

Use $(seq 1 $count) to generate numbers from 1 to count.

4
Add a final echo statement
Add a line after the loop that echoes "Storage accounts created successfully." to confirm completion.
Azure
Need a hint?

Use the echo command to print the message.