Updating a resource in an Azure Resource Manager template

  1. Home
  2. Updating a resource in an Azure Resource Manager template

Exam AZ-303 is retired. AZ-305 replacement is available.

This tutorial will explain you the process involved in Updating a resource in an Azure Resource Manager template. There are some scenarios in which you need to update a resource during a deployment. You might encounter this scenario when you cannot specify all the properties for a resource until other, dependent resources are created. For example, if you create a backend pool for a load balancer, you might update the network interfaces (NICs) on your virtual machines (VMs) to include them in the backend pool. And while Resource Manager supports updating resources during deployment, you must design your template correctly to avoid errors and to ensure the deployment is handled as an update.

Example template

Let’s look at an example template that demonstrates this. This deploys a virtual network named firstVNet that has one subnet named firstSubnet. It then deploys a virtual network interface (NIC) named nic1 and associates it with our subnet. Then, a deployment resource named updateVNet includes a nested template that updates our firstVNet resource by adding a second subnet named secondSubnet.

Let’s take a look at the resource object for our firstVNet resource first. Notice that we specify again the settings for our firstVNet in a nested template—this is because Resource Manager doesn’t allow the same deployment name within the same template and nested templates are considered to be a different tone. By again specifying our values for our firstSubnet resource, we are telling Resource Manager to update the existing resource instead of deleting it and redeploying it. Finally, our new settings for secondSubnet are picked up during this update.

Trying the template

An example is available on GitHub. To deploy the template, run the following Azure CLI commands:

az group create –location –name
az group deployment create -g \
–template-uri https://raw.githubusercontent.com/mspnp/template-examples/master/example1-update/deploy.json

Once deployment has finished, open the resource group you specified in the portal. You see a virtual network named firstVNet and a NIC named nic1. Click firstVNet, then click subnets. You see the firstSubnet that was originally created, and you see the secondSubnet that was added in the updateVNet resource.

Original subnet and updated subnet
Image Source – Microsoft

Then, go back to the resource group and click nic1 then click IP configurations. In the IP configurations section, the subnet is set to firstSubnet (10.0.0.0/24).

Updating a resource in an Azure Resource Manager template
Image Source – Microsoft

The original firstVNet has been updated instead of re-created. If firstVNet had been re-created, nic1 would not be associated with firstVNet.

free practice test for AZ- 303

Go back to home page

Reference documentation – Update a resource in an Azure Resource Manager template

Menu