In this hands-on lab, you will export an existing Azure Resource Manager (ARM) template that describes an Azure Cosmos DB for NoSQL account and database. Then, you will store it as a template spec in the lab subscription. After editing the template spec to make two changes to the Cosmos DB account resources, you will use the Cloud Shell to deploy the changed ARM template and then confirm the changes in the Azure portal.
If you are comfortable navigating the Azure portal, and have at least some experience with basic ARM templates and Azure CLI commands, you will have the best opportunity to successfully complete the lab objectives without assistance. Novices, however, are provided with enough information, tips, and hints to work on their own as much as possible before making use of the lab guide and solution videos.
Successfully complete this lab by achieving the following learning objectives:
- Open an incognito or in-private window, and log in to the Azure portal using the username and password provided in the lab environment.
- From within the portal, initiate the Cloud Shell, and when prompted, select a Bash shell (versus PowerShell). When prompted again, set up the backing storage. Be sure that you select Show advanced settings and not Create storage. The latter will cause an error. Set up a new storage account with a universally unique name.
- Wait for the command prompt to appear.
- Export and Save an ARM Template as a Template Spec
In this objective, you will use the existing Azure Cosmos for NoSQL account as the basis for creating a template spec and then update that template spec to change the default consistency level for the account and to create a new container.
- Navigate to the Azure Cosmos DB account predeployed in the lab environment.
- View the account’s ARM template, and launch the wizard to add the template to the template spec library.
- Work through the wizard, including editing the template to perform the following actions:
- Change the default consistency level for the Cosmos DB account from Session to Eventual.
- Create another container in the LabDB database that is identical to the existing container called LabContainer, and assign it this exact name: AnotherLabContainer.
- Confirm the template is stored in the template spec library.
Tips and Hints
- You may find it easier to edit the template JSON using the editor in Cloud Shell or an IDE, such as Visual Studio Code.
- If you decide to copy-paste existing container-related resources in the template, be sure to replace any references to the existing LabContainer.
Hint: In every case, there is more than one place you need to edit.
- If you do not specify container throughput settings, the deployment will default to a provisioned throughput of 400 RU/s.
- Deploy Template Spec Using Cloud Shell
In this objective, you will use the Azure CLI in the Cloud Shell to apply the changes you made in the ARM template stored in the template specs library.
- Navigate to the Cloud Shell you initialized in the housekeeping task. If the Cloud Shell has timed out, reconnect.
- Use the Azure CLI at the command prompt to list the template specs currently stored in the Azure subscription.
- Use the Azure CLI and the information provided in the prior step to show the details of the template spec you created in the last objective.
- Use the Azure CLI and the information provided in the prior step to deploy the template spec into the existing resource group, with the intended effect of updating the default consistency level on the existing Cosmos DB account and adding a new container to the existing LabDB database.
- When the deployment is complete, navigate to the Cosmos DB account in the Azure portal to confirm the changes expressed in the ARM template are reflected on the resource.
Tips and Hints
- The base command to list template specs is
az ts list.
- The base command to show the specific details in a given template spec is
az ts show, and you will need to pass the
- The base command to deploy resources in the Azure CLI is
az deployment group create.
- The arguments required to deploy resources using a template spec include, at a minimum,
- In order to fully identify the template spec you stored, you will need to append the template spec ID with
xis whatever version you last assigned when you stored the template spec.