Exercise - Run templates using Azure CLI

Completed

Important

To do these steps, you need an Azure subscription. If you don't have one already, you can create one by following the steps outlined on the Create your Azure free account today webpage.

Steps

In the following steps, we'll deploy the template and verify the result using Azure CLI:

  1. Create a resource group to deploy your resources to by running the following command:
az group create --name <resource group name> --location  <your nearest datacenter>

Note

Check the available region for you Choose the Right Azure Region for You. If you can't create in the nearest region, feel free to choose another one.

  1. From Cloud Shell, run the curl command to download the template you used previously from GitHub:
curl https://raw.githubusercontent.com/Microsoft/PartsUnlimited/master/Labfiles/AZ-400T05_Implementing_Application_Infrastructure/M01/azuredeploy.json > C:\temp\azuredeploy.json

  1. Validate the template by running the following command, replacing the values with your own:
az deployment group validate \
  --resource-group <rgn>[sandbox resource group name]</rgn> \
  --template-file C:\temp\azuredeploy.json \
  --parameters adminUsername=$USERNAME \
  --parameters adminPassword=$PASSWORD \
  --parameters dnsLabelPrefix=$DNS_LABEL_PREFIX

  1. Deploy the resource by running the following command, replacing the same values as earlier:
az deployment group create \
  --name MyDeployment \
  --resource-group <rgn>[sandbox resource group name]</rgn> \
  --template-file azuredeploy.json \
  --parameters adminUsername=$USERNAME \
  --parameters adminPassword=$PASSWORD \
  --parameters dnsLabelPrefix=$DNS_LABEL_PREFIX

  1. Obtain the IP address by running the following command:
    $IPADDRESS=$(az vm show \
      --name SimpleWinVM \
      --resource-group <rgn>[sandbox resource group name]</rgn> \
      --show-details \
      --query [publicIps] \
      --output tsv)

  1. Run curl to access your web server and verify that the deployment and running of the custom script extension were successful:
curl $IPADDRESS

You'll have the following output:

<html><body><h2>Welcome to Azure! My name is SimpleWinVM.</h2></body></html>

Note

Don't forget to delete any resources you deployed to avoid incurring extra costs from them.