{"id":3329,"date":"2022-05-14T16:02:43","date_gmt":"2022-05-14T16:02:43","guid":{"rendered":"https:\/\/exceedthecloud.com\/?p=3329"},"modified":"2022-05-14T16:02:47","modified_gmt":"2022-05-14T16:02:47","slug":"azure-deployments-using-resource-manager-templates","status":"publish","type":"post","link":"https:\/\/exceedthecloud.com\/?p=3329","title":{"rendered":"Azure Deployments Using Resource Manager Templates"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p>In this lab, you will create an Azure Resource Manager (ARM) template and modularize it by using the linked template concept. You will then modify the main deployment template to call the linked template and updated dependencies, and finally deploy the templates to Azure.<\/p>\n\n\n\n<p>After you complete this lab, you will be able to:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Create Resource Manager template<\/li><li>Create a Linked template for storage resources<\/li><li>Upload Linked Template to Azure Blob Storage and generate SAS token<\/li><li>Modify the main template to call Linked template<\/li><li>Modify main template to update dependencies<\/li><li>Deploy resources to Azure using linked templates<\/li><\/ul>\n\n\n\n<p>Review applications required for this lab<\/p>\n\n\n\n<p>Identify the applications that you\u2019ll use in this lab:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Microsoft Edge<\/li><li><a href=\"https:\/\/code.visualstudio.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Visual Studio Code<\/a>. This will be installed as part of prerequisites for this lab.<\/li><\/ul>\n\n\n\n<p><strong>Prepare an Azure subscription<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Identify an existing Azure subscription or create a new one.<\/li><li>Verify that you have a Microsoft account or an Azure AD account with the Owner role in the Azure subscription and the Global Administrator role in the Azure AD tenant associated with the Azure subscription.<\/li><\/ul>\n\n\n\n<p><strong>Lab 0: Configure the lab prerequisites<\/strong><\/p>\n\n\n\n<p>In this Lab, you will set up the prerequisites for the lab, which include Visual Studio Code.<\/p>\n\n\n\n<p><strong>Task 1: Install and configure Git and Visual Studio Code<\/strong><\/p>\n\n\n\n<p>In this task, you will install Visual Studio Code. If you have already implemented this prerequisite, you can proceed directly to the next task.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>If you don\u2019t have Visual Studio Code installed yet, from your lab computer, start a web browser, navigate to the\u00a0<a href=\"https:\/\/code.visualstudio.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Visual Studio Code download page<\/a>, download it, and install it.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Lab 1<\/strong>: <strong>Author and deploy Azure Resource Manager templates<\/strong><\/p>\n\n\n\n<p>In this lab, you will create an Azure Resource manager template and modularize it by using a linked template. You will then modify the main deployment template to call the linked template and updated dependencies, and finally deploy the templates to Azure.<\/p>\n\n\n\n<p><strong>Task 1: Create Resource Manager template<\/strong><\/p>\n\n\n\n<p>In this task, you will use Visual Studio Code to create a Resource Manager template<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>From your lab computer, start Visual Studio Code, in Visual Studio Code, click the\u00a0<strong>File<\/strong>\u00a0top level menu, in the dropdown menu, select\u00a0<strong>Preferences<\/strong>, in the cascading menu, select\u00a0<strong>Extensions<\/strong>, in the\u00a0<strong>Search Extensions<\/strong>\u00a0textbox, type\u00a0<strong>Azure Resource Manager (ARM) Tools<\/strong>, select the corresponding search result, and click\u00a0<strong>Install<\/strong>\u00a0to install the Azure Resource Manager Tools<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"493\" src=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/05\/Picture1-2.png\" alt=\"\" class=\"wp-image-3330\" srcset=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/05\/Picture1-2.png 624w, https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/05\/Picture1-2-300x237.png 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>In a web browser, connect to\u00a0<a href=\"https:\/\/github.com\/Azure\/azure-quickstart-templates\/blob\/master\/quickstarts\/microsoft.compute\/vm-simple-windows\/azuredeploy.json.\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>https:\/\/github.com\/Azure\/azure-quickstart-templates\/blob\/master\/quickstarts\/microsoft.compute\/vm-simple-windows\/azuredeploy.json<\/strong>.<\/a> Click on\u00a0<strong>Raw<\/strong>\u00a0option for the file. Copy the contents of the code window and paste it into Visual Studio Code editor.<\/li><\/ul>\n\n\n\n<p><strong>Note<\/strong>: Rather than creating a template from scratch we will use one of the\u00a0<a href=\"https:\/\/azure.microsoft.com\/en-us\/resources\/templates\/\" target=\"_blank\" rel=\"noreferrer noopener\">Azure Quickstart Templates<\/a>\u00a0named\u00a0<strong>Deploy a simple Windows template VM<\/strong>. The templates are downloadable the templates from GitHub &#8211;\u00a0<a href=\"https:\/\/github.com\/Azure\/azure-quickstart-templates\/blob\/master\/quickstarts\/microsoft.compute\/vm-simple-windows\" target=\"_blank\" rel=\"noreferrer noopener\">vm-simple-windows<\/a>.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\" start=\"2\"><li>On your lab computer, open File Explorer and create the following local folders that will serve to store templates:<ul><li><strong>C:\\templates<\/strong><\/li><li><strong>C:\\templates\\storage<\/strong><\/li><\/ul><\/li><li>Switch back to Visual Studio Code window with our azuredeploy.json template, click the\u00a0<strong>File<\/strong>\u00a0top level menu, in the dropdown menu, click\u00a0<strong>Save as<\/strong>, and save the template as\u00a0<strong>azuredeploy.json<\/strong>\u00a0in the newly created local folder\u00a0<strong>C:\\templates<\/strong>.<\/li><li>Review the template to get a better understanding of its structure. There are five resource types included in the template:<ul><li>Microsoft.Storage\/storageAccounts<\/li><li>Microsoft.Network\/publicIPAddresses<\/li><li>Microsoft.Network\/virtualNetworks<\/li><li>Microsoft.Network\/networkInterfaces<\/li><li>Microsoft.Compute\/virtualMachines<\/li><\/ul><\/li><li>In Visual Studio Code, save the file again, but this time choose\u00a0<strong>C:\\templates\\storage<\/strong>\u00a0as the destination and\u00a0<strong>storage.json<\/strong>\u00a0as the file name.<\/li><\/ul>\n\n\n\n<p><strong>Note<\/strong>: We now have two identical JSON files:&nbsp;<strong>C:\\templates\\azuredeploy.json<\/strong>&nbsp;and&nbsp;<strong>C:\\templates\\storage\\storage.json<\/strong>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Task 2: Create a Linked template for storage resources<\/strong><\/p>\n\n\n\n<p>In this task, you will modify the templates you saved in the previous task such that the linked storage template&nbsp;<strong>storage.json<\/strong>&nbsp;will create a storage account only, while its execution will be invoked by the first template. The linked storage template needs to pass a value back to the main template,&nbsp;<strong>azuredeploy.json<\/strong>, and this value will be defined in the outputs element of the linked storage template.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>In the\u00a0<strong>storage.json<\/strong>\u00a0file displayed in the Visual Studio Code window, under the\u00a0<strong>resources section<\/strong>, remove all the resource elements except the\u00a0<strong>storageAccounts<\/strong>\u00a0resource. It should result in a resource section looking as follows:<\/li><\/ul>\n\n\n\n<p>CodeCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\"resources\": &#91;\n  {\n    \"type\": \"Microsoft.Storage\/storageAccounts\",\n    \"name\": \"&#91;variables('storageAccountName')]\",\n    \"location\": \"&#91;parameters('location')]\",\n    \"apiVersion\": \"2021-04-01\",\n    \"sku\": {\n       \"name\": \"Standard_LRS\"\n    },\n    \"kind\": \"Storage\"\n  }\n],\n<\/code><\/pre>\n\n\n\n<p>Rename the name element of storageAccount from variables to parameters<\/p>\n\n\n\n<p>CodeCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\"resources\": &#91;\n  {\n    \"type\": \"Microsoft.Storage\/storageAccounts\",\n    \"name\": \"&#91;parameters('storageAccountName')]\",\n    \"location\": \"&#91;parameters('location')]\",\n    \"apiVersion\": \"2021-04-01\",\n    \"sku\": {\n       \"name\": \"Standard_LRS\"\n    },\n    \"kind\": \"Storage\",\n    \"properties\": {}\n  }\n],\n<\/code><\/pre>\n\n\n\n<p>Next, remove the entire variables section and all variable definitions:<\/p>\n\n\n\n<p>CodeCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\"variables\": {\n  \"storageAccountName\": \"&#91;concat('bootdiags', uniquestring(resourceGroup().id))]\",\n  \"nicName\": \"myVMNic\",\n  \"addressPrefix\": \"10.0.0.0\/16\",\n  \"subnetName\": \"Subnet\",\n  \"subnetPrefix\": \"10.0.0.0\/24\",\n  \"virtualNetworkName\": \"MyVNET\",\n  \"networkSecurityGroupName\": \"default-NSG\"\n},\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Next, remove all parameter values except location and add the following parameter code, resulting in the following outcome:<\/li><\/ul>\n\n\n\n<p>CodeCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\"parameters\": {\n  \"location\": {\n    \"type\": \"string\",\n    \"defaultValue\": \"&#91;resourceGroup().location]\",\n    \"metadata\": {\n      \"description\": \"Location for all resources.\"\n    }\n  },\n    \"storageAccountName\":{\n    \"type\": \"string\",\n    \"metadata\": {\n      \"description\": \"Azure Storage account name.\"\n    }\n  }\n},\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Next, update the output section to define a storageURI output value. The storageUri value is required by the virtual machine resource definition in the main template. You pass the value back to the main template as an output value. Modify the output so it looks like the below.<\/li><\/ul>\n\n\n\n<p>CodeCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\"outputs\": {\n  \"storageUri\": {\n    \"type\": \"string\",\n    \"value\": \"&#91;reference(parameters('storageAccountName')).primaryEndpoints.blob]\"\n  }\n}\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Last, make sure schema version is 2019-04-01 (ignore warnings\/errors if shown in VS Code) :<\/li><\/ul>\n\n\n\n<p>CodeCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n       \"$schema\": \"https:\/\/schema.management.azure.com\/schemas\/2019-04-01\/deploymentTemplate.json#\",\n       \"contentVersion\": \"1.0.0.0\",\n       \"parameters\": {\n         \"storageAccountName\":{\n           \"type\": \"string\",\n           \"metadata\": {\n             \"description\": \"Azure Storage account name.\"\n           }\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Save the storage.json template. The linked storage template should now look as follows:<\/li><\/ul>\n\n\n\n<p>CodeCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> {\n   \"$schema\": \"https:\/\/schema.management.azure.com\/schemas\/2019-04-01\/deploymentTemplate.json#\",\n   \"contentVersion\": \"1.0.0.0\",\n   \"metadata\": {\n     \"_generator\": {\n       \"name\": \"bicep\",\n       \"version\": \"0.4.1.14562\",\n       \"templateHash\": \"8381960602397537918\"\n     }\n   },\n   \"parameters\": {\n     \"location\": {\n       \"type\": \"string\",\n       \"defaultValue\": \"&#91;resourceGroup().location]\",\n       \"metadata\": {\n         \"description\": \"Location for all resources.\"\n       }\n     },\n     \"storageAccountName\": {\n       \"type\": \"string\",\n       \"metadata\": {\n         \"description\": \"Azure Storage account name.\"\n       }\n     }\n    \n   },\n   \"functions\": &#91;],\n   \"variables\": {\n   },\n   \"resources\": &#91;\n     {\n       \"type\": \"Microsoft.Storage\/storageAccounts\",\n       \"apiVersion\": \"2021-04-01\",\n       \"name\": \"&#91;parameters('storageAccountName')]\",\n       \"location\": \"&#91;parameters('location')]\",\n       \"sku\": {\n         \"name\": \"Standard_LRS\"\n       },\n       \"kind\": \"Storage\"\n     }\n   ],\n   \"outputs\": {\n     \"storageUri\": {\n       \"type\": \"string\",\n       \"value\": \"&#91;reference(parameters('storageAccountName')).primaryEndpoints.blob]\"\n     }\n   }\n }\n<\/code><\/pre>\n\n\n\n<p><strong>Task 3: Upload Linked Template to Azure Blob Storage and generate SAS token<\/strong><\/p>\n\n\n\n<p>In this task, you will upload the linked template you created in the previous task to Azure Blob Storage and generate SAS token to provide access to it during subsequent deployments.<\/p>\n\n\n\n<p><strong>Note<\/strong>: When linking to a template, the Azure Resource Manager service must be able to access it via either http or https. In order to accomplish this, you will upload the linked storage template,&nbsp;<strong>storage.json<\/strong>, to blob storage in Azure. Then you will generate a digitally signed URL that provides a limited access to that corresponding blob. You will perform these steps by using Azure CLI in Azure Cloud Shell. Alternatively, you could manually create a blob container via the Azure Portal, upload the file and generate a URL or use either Azure CLI or Azure PowerShell modules installed on your lab computer.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>On the lab computer, start a web browser and navigate to the\u00a0<a href=\"https:\/\/portal.azure.com\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Azure Portal<\/strong><\/a>, and sign in with the user account that has at least the Contributor role in the Azure subscription you will be using in this lab.<\/li><li>In the Azure portal, in the toolbar, click the\u00a0<strong>Cloud Shell<\/strong>\u00a0icon located directly to the right of the search text box.<\/li><\/ul>\n\n\n\n<p><strong>Note<\/strong>: Alternatively, you can navigate to\u00a0<a href=\"http:\/\/shell.azure.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Azure Cloud Shell<\/a>\u00a0directly.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\" start=\"3\"><li>If prompted to select either\u00a0<strong>Bash<\/strong>\u00a0or\u00a0<strong>PowerShell<\/strong>, select\u00a0<strong>PowerShell<\/strong>.<\/li><\/ul>\n\n\n\n<p><strong>Note<\/strong>: If this is the first time you are starting&nbsp;<strong>Cloud Shell<\/strong>&nbsp;and you are presented with the&nbsp;<strong>You have no storage mounted<\/strong>&nbsp;message, select the subscription you are using in this lab, and select&nbsp;<strong>Create storage<\/strong>.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\" start=\"4\"><li>From a\u00a0<strong>PowerShell<\/strong>\u00a0session in the Cloud Shell pane, run the following to create a blob storage container, upload the template file you created in the previous task, and generate a SAS token that you will reference in the main template to access the linked template.<\/li><li>First, copy and paste the following lines of code to set a value for the Azure region you want to deploy to. The command will wait for your input as shown in the prompt.<\/li><\/ul>\n\n\n\n<p>CodeCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Provide the name of the closest Azure region in which you can provision Azure VMs\n$location = \u2018eastus\u2019\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Second, copy and paste the following code into the same Cloud Shell session to create a blob storage container:<\/li><\/ul>\n\n\n\n<p>CodeCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> # This is a random string used to assign the name to the Azure storage account\n $suffix = Get-Random\n $resourceGroupName = 'exceedm13l01-RG'\n $storageAccountName = 'exceedm13blob' + $suffix\n\n # The name of the Blob container to be created\n $containerName = 'linktempblobcntr' \n\n # A file name used for downloading and uploading the linked template\n $fileName = 'storage.json' \n    \n # Create a resource group\n New-AzResourceGroup -Name $resourceGroupName -Location $location \n    \n # Create a storage account\n $storageAccount = New-AzStorageAccount `\n   -ResourceGroupName $resourceGroupName `\n   -Name $storageAccountName `\n   -Location $location `\n   -SkuName 'Standard_LRS'\n    \n $context = $storageAccount.Context\n    \n # Create a container\n New-AzureStorageContainer -Name $containerName -Context $context\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"223\" src=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/05\/Picture2-2.png\" alt=\"\" class=\"wp-image-3331\" srcset=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/05\/Picture2-2.png 624w, https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/05\/Picture2-2-300x107.png 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>In the Cloud Shell pane, click the\u00a0<strong>Upload\/download files<\/strong>\u00a0icon and, in the dropdown menu, click\u00a0<strong>Upload<\/strong>. In the\u00a0<strong>Open<\/strong>\u00a0dialog box, navigate to and select\u00a0<strong>C:\\templates\\storage\\storage.json<\/strong>\u00a0and click\u00a0<strong>Open<\/strong>.<\/li><\/ul>\n\n\n\n<p>CodeCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Upload the linked template\n Set-AzureStorageBlobContent `\n   -Container $containerName `\n   -File \"$home\/$fileName\" `\n   -Blob $fileName `\n   -Context $context\n\n # Generate a SAS token. We set an expiry time of 24 hours, but you could have shorter values for increased security.\n $templateURI = New-AzureStorageBlobSASToken `\n   -Context $context `\n   -Container $containerName `\n   -Blob $fileName `\n   -Permission r `\n   -ExpiryTime (Get-Date).AddHours(24.0) `\n   -FullUri\n\n \"Resource Group Name: $resourceGroupName\"\n \"Linked template URI with SAS token: $templateURI\"\n<\/code><\/pre>\n\n\n\n<p><strong>Note<\/strong>: Make sure to record the final output generated by the script. You will need it later in the lab.<\/p>\n\n\n\n<p><strong>Note<\/strong>: The output values should resemble the following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"301\" src=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/05\/Picture3-2.png\" alt=\"\" class=\"wp-image-3332\" srcset=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/05\/Picture3-2.png 624w, https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/05\/Picture3-2-300x145.png 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/figure>\n\n\n\n<p>CodeCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Resource Group Name: exceedm13l01-RG\n      Linked template URI with SAS token: https:\/\/exceedm13blob1677205310.blob.core.windows.net\/linktempblobcntr\/storage.json?sv=2018-03-28&amp;sr=b&amp;sig=B4hDLt9rFaWHZXToJlMwMjejAQGT7x0INdDR9bHBQnI%3D&amp;se=2020-11-23T21%3A54%3A53Z&amp;sp=r\n<\/code><\/pre>\n\n\n\n<p><strong>Note<\/strong>: For scenarios requiring increased level of security, you could generate a SAS token dynamically during main template deployment and assign the SAS token a shorter validity period.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Close the Cloud Shell pane.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Task 4: Modify the main template to call the linked template<\/strong><\/p>\n\n\n\n<p>In this task, you will modify the main template to reference the linked template you uploaded to Azure Blob Storage in the previous task.<\/p>\n\n\n\n<p><strong>Note<\/strong>: To account for the changes we made to the templates structure by modularizing all the storage elements, we now need to modify the main template to call the new storage resource definition.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>In Visual Studio Code, click the\u00a0<strong>File<\/strong>\u00a0top level menu, in the dropdown menu, select\u00a0<strong>Open File<\/strong>, in the Open File dialog box, navigate to\u00a0<strong>C:\\templates\\azuredeploy.json<\/strong>, select it, and click\u00a0<strong>Open<\/strong>.<\/li><li>In the\u00a0<strong>azuredeploy.json<\/strong>\u00a0file, in the resource section remove the storage resource element<\/li><\/ul>\n\n\n\n<p>CodeCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"type\": \"Microsoft.Storage\/storageAccounts\",\n  \"name\": \"&#91;variables('storageAccountName')]\",\n  \"location\": \"&#91;parameters('location')]\",\n  \"apiVersion\": \"2021-04-01\",\n  \"sku\": {\n    \"name\": \"Standard_LRS\"\n  },\n  \"kind\": \"Storage\"\n},\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Next, add the following code directly in the same location where the newly deleted storage resource element was:<\/li><\/ul>\n\n\n\n<p><strong>Note<\/strong>: Make sure to replace the&nbsp;&lt;linked_template_URI_with_SAS_token&gt;&nbsp;placeholder with its actual value that you recorded at the end of the previous task.<\/p>\n\n\n\n<p>CodeCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"name\": \"linkedTemplate\",\n  \"type\": \"Microsoft.Resources\/deployments\",\n  \"apiVersion\": \"2018-05-01\",\n  \"properties\": {\n      \"mode\": \"Incremental\",\n      \"templateLink\": {\n          \"uri\":\"&lt;linked_template_URI_with_SAS_token>\"\n      },\n      \"parameters\": {\n          \"storageAccountName\":{\"value\": \"&#91;variables('storageAccountName')]\"},\n          \"location\":{\"value\": \"&#91;parameters('location')]\"}\n      }\n   }\n},\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Review the following details in the main template:<ul><li>A Microsoft.Resources\/deployments resource in the main template is used to link to another template.<\/li><li>The deployments resource has a name called linkedTemplate. This name is used for configuring dependency.<\/li><li>You can only use Incremental deployment mode when calling linked templates.<\/li><li>templateLink\/uri contains the linked template URI.<\/li><li>Use parameters to pass values from the main template to the linked template.<\/li><\/ul><\/li><li>Save the template.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Task 5: Modify main template to update dependencies<\/strong><\/p>\n\n\n\n<p>In this task, you will modify the main template to account for remaining dependencies that need to be updated.<\/p>\n\n\n\n<p><strong>Note<\/strong>: Since the storage account is defined in the linked storage template, you need to update the&nbsp;<strong>Microsoft.Compute\/virtualMachines<\/strong>&nbsp;resource definition.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>In the resource section in the virtual machines element, update the\u00a0<strong>dependsOn<\/strong>\u00a0element by replacing:<\/li><\/ul>\n\n\n\n<p>CodeCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\"dependsOn\": &#91;\n  \"&#91;resourceId('Microsoft.Network\/networkInterfaces\/', variables('nicName'))]\",\n  \"&#91;resourceId('Microsoft.Storage\/storageAccounts\/', variables('storageAccountName'))]\"\n]\n<\/code><\/pre>\n\n\n\n<p>with<\/p>\n\n\n\n<p>CodeCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\"dependsOn\": &#91;\n      \n  \"&#91;resourceId('Microsoft.Network\/networkInterfaces\/', variables('nicName'))]\",\n  \"linkedTemplate\"\n]\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>In the resources section under the\u00a0<strong>Microsoft.Compute\/virtualMachines<\/strong>\u00a0element, reconfigure the\u00a0<strong>properties\/diagnosticsProfile\/bootDiagnostics\/storageUri<\/strong>\u00a0element to reflect the output value you defined in the linked storage template by replacing:<\/li><\/ul>\n\n\n\n<p>CodeCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\"diagnosticsProfile\": {\n  \"bootDiagnostics\": {\n    \"enabled\": true,\n    \"storageUri\": \"&#91;reference(resourceId('Microsoft.Storage\/storageAccounts\/', variables('storageAccountName'))).primaryEndpoints.blob]\"\n  }\n<\/code><\/pre>\n\n\n\n<p>with<\/p>\n\n\n\n<p>CodeCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\"diagnosticsProfile\": {\n  \"bootDiagnostics\": {\n    \"enabled\": true,\n    \"storageUri\": \"&#91;reference('linkedtemplate').outputs.storageUri.value]\"\n  }\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>Save the updated main deployment template.<\/li><\/ul>\n\n\n\n<p><strong>Task 6: Deploy resources to Azure by using linked templates<\/strong><\/p>\n\n\n\n<p><strong>Note<\/strong>: You can deploy templates in several ways, such as directly from the Azure Portal, by using Azure CLI or PowerShell installed locally or from the Azure Cloud Shell. In this lab, you will use Azure CLI from the Azure Cloud Shell.<\/p>\n\n\n\n<p><strong>Note<\/strong>: To use Azure Cloud Shell, you will upload the main deployment template, azuredeploy.json into your Cloud Shell\u2019s home directory. Alternatively, you could also upload it to Azure Blob Storage, just as you did upload the linked template, and reference it by using its URI rather than local file system path.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>On the lab computer, in the web browser displaying the Azure Portal, click the\u00a0<strong>Cloud Shell<\/strong>\u00a0icon to open Cloud Shell.<\/li><\/ul>\n\n\n\n<p><strong>Note<\/strong>: If you have the PowerShell session from earlier in this Lab still active, you can use this without switching to Bash (next step). The following steps can be run in both a PowerShell and Bash session of Cloud Shell. If you are opening a new Cloud Shell session, follow the instructions.<\/p>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\" start=\"2\"><li>In the Cloud Shell pane, click\u00a0<strong>PowerShell<\/strong>, in the dropdown menu, click\u00a0<strong>Bash<\/strong>\u00a0and, when prompted, click\u00a0<strong>Confirm<\/strong>.<\/li><li>In the Cloud Shell pane, click the\u00a0<strong>Upload\/download files<\/strong>\u00a0icon and, in the dropdown menu, click\u00a0<strong>Upload<\/strong>.<\/li><li>In the\u00a0<strong>Open<\/strong>\u00a0dialog box, navigate to and select\u00a0<strong>C:\\templates\\azuredeploy.json<\/strong>\u00a0and click\u00a0<strong>Open<\/strong>.<\/li><li>From a\u00a0<strong>Bash<\/strong>\u00a0session in the Cloud Shell pane, run the following to perform a deployment by using a newly uploaded template:<\/li><\/ul>\n\n\n\n<p>CodeCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>az deployment group create --name exceedm13l01deployment --resource-group exceedm13l01-RG --template-file azuredeploy.json<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\" type=\"1\"><li>When prompted to provide the value for \u2018adminUsername\u2019, type\u00a0<strong>Student<\/strong>\u00a0and press the\u00a0<strong>Enter<\/strong>\u00a0key.<\/li><li>When prompted to provide the value for \u2018adminPassword\u2019, type\u00a0<strong>Pa55w.rd1234<\/strong>\u00a0and press the\u00a0<strong>Enter<\/strong>\u00a0key. (Password typing will not be shown)<\/li><li>If you receive errors when running the above command to deploy the template, try the following:<ul><li>If you have multiple Azure subscriptions ensure you have set the subscription context to the correct one where the resource group is deployed.<\/li><li>Ensure that the linked template is accessible via the URI you specified.<\/li><\/ul><\/li><\/ul>\n\n\n\n<p><strong>Note<\/strong>: As a next step, you could now modularize the remaining resource definitions in the main deployment template, such as the network and virtual machine resource definitions.<\/p>\n\n\n\n<p><strong>Note<\/strong>: If you are not planning on using the deployed resources, you should delete them to avoid associated charges. You can do so simply by deleting the resource group\u00a0<strong>exceedm13l01-RG<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"159\" src=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/05\/Picture4-2.png\" alt=\"\" class=\"wp-image-3333\" srcset=\"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/05\/Picture4-2.png 624w, https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/05\/Picture4-2-300x76.png 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Review<\/strong><\/p>\n\n\n\n<p>In this lab, you learned how to create an Azure Resource manager template, modularize it by using a linked template, modify the main deployment template to call the linked template and updated dependencies, and finally deploy the templates to Azure.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><mark class=\"kt-highlight\">Reminder: Don\u2019t forget to delete or shutdown all unused Azure resources after your labs for cost saving<\/mark><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this lab, you will create an Azure Resource Manager (ARM) template and modularize it by using the linked template concept. You will then modify the main deployment template to call the linked template and updated dependencies, and finally deploy &hellip; <a href=\"https:\/\/exceedthecloud.com\/?p=3329\">Continued<\/a><\/p>\n","protected":false},"author":1,"featured_media":3335,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"kt_blocks_editor_width":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4,19],"tags":[90,110,35,54],"class_list":["post-3329","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-practical-labs-series","category-virtual-machines","tag-arm","tag-github","tag-virtual-machines","tag-visual-studio-code"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/exceedthecloud.com\/wp-content\/uploads\/2022\/05\/istockphoto-1199694568-612x612-1.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=\/wp\/v2\/posts\/3329","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3329"}],"version-history":[{"count":1,"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=\/wp\/v2\/posts\/3329\/revisions"}],"predecessor-version":[{"id":3334,"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=\/wp\/v2\/posts\/3329\/revisions\/3334"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=\/wp\/v2\/media\/3335"}],"wp:attachment":[{"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/exceedthecloud.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}