Cloud Vendor | Microsoft Azure |
Proficiency Level | Cloud Enthusiast |
Tags | AutomationAzure ARMAzure PowerShellAzure StorageCI/CDPowerShell |
Summary
In this lab, you will create an Azure Storage Account using Azure Resource Manager (ARM) and Azure PowerShell. You will use the command line to run PowerShell cmdlets that will sign you in to Azure and deploy the ARM template.
Each exercise below builds upon the previous one. You should start each new exercise from the last step of the previous exercise unless it is explicitly written otherwise.
Learning Objectives
After completion of this lab, you will be able to:
- Understand Azure Resource Manager (ARM) templates
- Use Azure PowerShell cmdlets to sign in to Azure
- Use Azure PowerShell cmdlets to select Azure Subscription
- Use Azure PowerShell to deploy an ARM template to Azure
Prerequisites
To complete this lab, you will need the following:
- Reliable internet connection
- A work, school or personal Microsoft Account used to access Microsoft Azure Management Portal
- A subscription for Microsoft Azure
- PowerShell Core installed on your laptop (Windows, Mac or Linux)
- Azure PowerShell cmdlets installed on your laptop
Exercise #1: Sign In To Azure Using Azure PowerShell
In this exercise, you will sign in to Azure using Azure PowerShell and select a subscription to work with.
Steps
- Start a PowerShell command window on your laptop
- Type the following command at the prompt
Connect-AzAccount
- Follow the printed instructions to sign in to Azure using your browser
- Once you are signed in, the default subscription for your account will be printed
- Milestone step: At this point, you have learned how to sign in to Azure from a PowerShell command window
- Type the following command at the prompt
Get-AzSubscription
- That will print a list of all subscriptions you have access to with your account
- Milestone step: At this point, you have learned how to list all Azure subscriptions you have access to from a PowerShell command window
- Copy the
Id
of the subscription you want to use for the deployment - Type the following command at the prompt
Select-AzSubscription -SubscriptionId [subscription_to_use]
- That will print the details of the subscription you will use for the deployment
- Milestone step: At this point, you have learned how to select an Azure subscription to deploy resources from a PowerShell command window
Exercise #2: Deploy an ARM Template Using Azure PowerShell
In this exercise, you will create a new resource group and deploy an ARM template that creates a Storage Account using Azure PowerShell.
Steps
- Open a code editor and paste the following code in it
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "storageAccount_name": { "defaultValue": "[first_name_and_initials]autlab01str", "type": "String" } }, "variables": {}, "resources": [ { "type": "Microsoft.Storage/storageAccounts", "apiVersion": "2019-04-01", "name": "[parameters('storageAccount_name')]", "location": "westus2", "tags": { "Application": "Training", "Owner": "[owner_name]", "OwnerEmail": "[owner_email]", "Purpose": "Education", "Version": "1.0" }, "sku": { "name": "Standard_LRS", "tier": "Standard" }, "kind": "StorageV2", "properties": { "networkAcls": { "bypass": "AzureServices", "virtualNetworkRules": [], "ipRules": [], "defaultAction": "Allow" }, "supportsHttpsTrafficOnly": true, "encryption": { "services": { "file": { "enabled": true }, "blob": { "enabled": true } }, "keySource": "Microsoft.Storage" }, "accessTier": "Hot" } }, { "type": "Microsoft.Storage/storageAccounts/blobServices", "apiVersion": "2019-04-01", "name": "[concat(parameters('storageAccount_name'), '/default')]", "dependsOn": [ "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccount_name'))]" ], "properties": { "cors": { "corsRules": [] }, "deleteRetentionPolicy": { "enabled": false } } } ] }
- Make the following modifications in the above code
Line 6 → Replace[first_name_and_initials]
with your first name and initials
Line 19 → Replace[owner_name]
with your name
Line 20 → Replace[owner_email]
with your email - Save the file in your home folder with the following name
template.json
- In your PowerShell command window, change the path to your home folder
- Type the following command in your PowerShell command window
New-AzResourceGroup -ResourceGroupName '[first_name_and_initials]automationlab01-rg' -Location 'westus2'
- Milestone step: At this point, you have learned how to create a new Resource Group in Azure using the Azure PowerShell cmdlets
- Type the following command in your PowerShell command window
New-AzResourceGroupDeployment -ResourceGroupName '[first_name_and_initials]automationlab01-rg' -TemplateFile 'template.json'
- Once the deployment is complete, you will see a summary of the deployed resources printed in the command window
- Milestone step: At this point, you have learned how to create a new Resource Group deployment in Azure using the Azure PowerShell cmdlets and ARM templates
- Verify that the new resource group and storage account are available in Azure Management Portal
Last Update: November 5, 2019