Exam AZ-103: Microsoft Azure Administrator is retired. AZ-104 is available.

Modify Azure Resource Manager template

We often see some scenarios in which we need to update a resource during a deployment. Such that we must encounter this scenario when we cannot specify all the properties for a resource until other, dependent resources are created. For instance in case we need create a backend pool for a load balancer, we might update the network interfaces (NICs) on your virtual machines (VMs) to include them in the backend pool. While Resource Manager supports updating resources during deployment, we must also design the template correctly to avoid errors and to ensure the deployment is handled as an update.

The process of modifying azure resource manager template

  • Firstly, we must reference the resource once in the template to create it and then reference the resource by the same name to update it later. Such that, if two resources have the same name in a template, Resource Manager throws an exception. In order to avoid this error, specify the updated resource in a second template that’s either linked or included as a subtemplate using the Microsoft.Resources/deployments resource type.
  • Secondly, we must either specify the name of the existing property to change or a new name for a property to add in the nested template. Also we must specify the original properties and their original values. In case we fail to provide the original properties and values, Resource Manager assumes we want to create a new resource and deletes the original resource.

Configure the location of new VMs

There are a lot of scenarios in which we would want to move the existing Azure IaaS virtual machines (VMs) from one region to another. For instance, if we want to improve reliability and availability of existing VMs, to improve manageability, or to move for governance reasons.

Following are the steps to display how to prepare the virtual machine for the move using Azure Site Recovery as a solution.

  • Create the vault in any region, except the source region
  • Sign in to the Azure portal > Recovery Services.
  • Select Create a resource > Management Tools > Backup and Site Recovery.
  • In Name, specify the friendly name ContosoVMVault. If you have more than one subscription, select the appropriate one.
  • Create the resource group ContosoRG.
  • Specify an Azure region. To check supported regions, see geographic availability in Azure Site Recovery pricing details.
  • In Recovery Services vaults, select Overview > ContosoVMVault > +Replicate.
  • In Source, select Azure.
  • In Source location, select the source Azure region where your VMs are currently running.
  • Select the Resource Manager deployment model. Then select the Source subscription and Source resource group.
  • Select OK to save the settings.

Configure VHD template

In order to create a new VM by attaching a specialized managed disk as the OS disk. Such that a specialized disk is a copy of a virtual hard disk (VHD) from an existing VM that contains the user accounts, applications, and other state data from your original VM.

Now when we use a specialized VHD to create a new VM, the new VM retains the computer name of the original VM. Other computer-specific information is also kept and, in some cases, this duplicate information could cause issues. When copying a VM, be aware of what types of computer-specific information your applications rely on.

  • Option 1: Use an existing disk – If you had a VM that you deleted and you want to reuse the OS disk to create a new VM, use Get-AzDisk.
  • Option 2: Upload a specialized VHD – We can upload the VHD from a specialized VM created with an on-premises virtualization tool, like Hyper-V, or a VM exported from another cloud. Create a storage account. We would need the name of the resource group where the storage account will be created. Use Get-AzResourceGroup see all the resource groups that are in the subscription. Create a resource group named myResourceGroup in the West US region.Create a storage account named mystorageaccount in the new resource group by using the New-AzStorageAccount cmdlet.
  • Option 3: Copy an existing Azure VM – We can create a copy of a VM that uses managed disks by taking a snapshot of the VM, and then by using that snapshot to create a new managed disk and a new VM.

Deploy from template

In order to create a Windows virtual machine by using an Azure Resource Manager template and Azure PowerShell from the Azure Cloud shell.

Create a virtual machine

In order to create an Azure virtual machine usually includes two steps –

  • Creating a resource group – An Azure resource group is a logical container into which Azure resources are deployed and managed. A resource group must be created before a virtual machine.
  • Creating a virtual machine – In case we choose to install and use the PowerShell locally instead of from the Azure Cloud shell. Run Get-Module -ListAvailable Az to find the version. Also in case we need to upgrade, see Install Azure PowerShell module. In case we are running PowerShell locally, then we also need to run Connect-Az Account to create a connection with Azure.

Save a deployment as an Azure Resource Manager template

In the process of creating a VM in Azure using the portal or PowerShell, a Resource Manager template is automatically created. Such that we can use this template to quickly duplicate a deployment. Also the template contains information about all of the resources in a resource group. In case of a virtual machine, this indicates the template contains everything that is created in support of the VM in that resource group, including the networking resources.

Steps to Download the template using the portal?

  • Log in to the Azure portal.
  • One the left menu, select Virtual Machines.
  • Select the virtual machine from the list.
  • Select Export template.
  • Select Download from the menu at the top and save the .zip file to the local computer.
  • Open the .zip file and extract the files to a folder. The .zip file contains – deploy.ps1, deploy.sh, deployer.rb, DeploymentHelper.cs, parameters.json, template.json,
  • The template.json file is the template.

How to download the template using PowerShell?

Remember we can also download the .json template file using the Export-AzResourceGroup cmdlet. We can also use the -path parameter to provide the filename and path for the .json file.

Deploy Windows VMs

How to create a virtual machine?

Following are the steps for creating an Azure virtual machine –

  • Create a resource group – An Azure resource group is a logical container into which Azure resources are deployed and managed. A resource group must be created before a virtual machine.
  • Create a virtual machine

In case we choose to install and use the PowerShell locally instead of from the Azure Cloud shell, then it would require the Azure PowerShell module. Run Get-Module -ListAvailable Az to find the version. In case we need to upgrade, Install Azure PowerShell module. For running PowerShell locally, we also need to run Connect-AzAccount to create a connection with Azure.

Deploy Linux VMs

We shall now learn to create a Linux Virtual Machine with Azure Resource Manager Templates. Azure Resource Manager templates are JSON files that define the infrastructure and configuration of your Azure solution. Such that by using a template, we can repeatedly deploy the solution throughout its lifecycle and have confidence that the resources are deployed in a consistent state.

How to create a virtual machine?

The process of creating an Azure virtual machine usually involves the following steps –

  • Creating a resource group – An Azure resource group is a logical container into which Azure resources are deployed and managed. A resource group must be created before a virtual machine.
  • Create a virtual machine
Menu