Understand instance count changes in a JSON file with Azure

Understand instance count changes in a JSON file with Azure

Q. I am using JSON templates to deploy VMs but when I decrease the number of instances the VMs are not deleted. Why?

A. Within a JSON template you can configure the instance count which enables multiple instances of the VM to be deployed. One benefit of JSON templates is you can modify the JSON template then redeploy and only changes are implemented, for example increasing the instance count will result in the additional VMs being created however if you decrease the instance count then no VMs are deleted. The reason for this is there are two modes to apply JSON templates (via the -Mode arguement); incremental and complete with incremental being the default.

When the incremental mode is used any resources that exist in the resource group that does not exist in the template is unchanged and only new resources are added with existing resource left alone. This is why reducing the instance count does not remove VMs.

If you specify the complete deployment mode then any resources found in the resource group that are not in the template are removed (which would delete VMs if instance count is reduced) in addition to new resources in the template being added and existing left alone.

However even if you use complete and it deletes VMs it does not delete the virtual hard disks for the removed VMs which means if the instance count was increased in the future you would likely see problems when the new VMs attempted to use the same VHD names that already exist.

The instance count is really not designed as a scaling mechanism and a better option is the new VM Scale Set functionality with managed disks.

More information on the deployment modes can be found at https://azure.microsoft.com/en-us/documentation/articles/resource-group-template-deploy/#incremental-and-complete-deployments.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.