Modify an existing ARM template
Often you will need to modify a template that you have previously used to change the configu- ration. As previously mentioned, one of the key benefits of using templates to describe your infrastructure (commonly referred to as Infrastructure as Code) is so you can modify it and deploy it in a versioned manner. To accommodate this behavior, ARM supports two different deployment modes: Complete and Incremental.
ARM template Complete mode
In Complete mode, Azure Resource Manager deletes resources that exist in the resource group that are not in the template. This is helpful if you need to remove a resource from Azure and you want to make sure your template matches the deployment. You can remove the resource from the template, deploy using Complete mode, and it will be removed. You should consider using the what-if parameter when using Complete mode as a test before actually submitting it for deployment.
ARM template Incremental mode
In Incremental mode, Azure Resource Manager leaves unchanged any resources that exist in the resource group but aren’t in the template. It will update the resources in the resource group if the settings in the template differ from what is deployed. Incremental mode can have unintended impacts on resource properties. If your template doesn’t cover all the properties of a resource, then at the time of deployment, unspecified properties will be reset to default values that can potentially affect the environment.
Incremental is the default mode for the Azure portal and when you are deploying through the command-line tools or Visual Studio. To use Complete mode, you must use the REST API or the command-line tools with the -Mode/–mode parameter set to Complete.
The following example deploys a template in Complete mode using PowerShell:
New-AzResourceGroupDeployment `
-Mode Complete `
-Name simpleVMDeployment `
-ResourceGroupName ExamRefRG `
-TemplateFile C:\ARMTemplates\deploy.json
The next example deploys a template in Complete mode using the Azure CLI:
az group deployment create \
–name simpleVMDeployment \
–mode Complete \
–resource-group ExamRefRG \
–template-file deploy.json
Configure a VHD template
It is assumed that you already know the structure of the ARM template. For detailed structure and syntax, please refer to https://learn.microsoft.com/en-us/azure/azure-resource-manager/ templates/syntax.
In the storageProfile section of a virtual machine resource, you can specify the imageRefer- ence element that references an image from the Azure Marketplace:
“imageReference”: {
“publisher”: “[variables(‘VMImagePublisher’)]”, “offer”: “[variables(‘VMImageOffer’)]”,
“sku”: “[parameters(‘VMOSVersion’)]”, “version”: “latest”
}
You also can specify a generalized VHD that you have previously created. To specify a user image, you must specify the osType property (Windows or Linux), the URL to the VHD itself, and the URL to where the disk will be created in Azure Storage (osDiskVhdName). The follow- ing alternative code snippet demonstrates this. (This sample does not build on the previous example.)
“storageProfile”: { “osDisk”: {
“name”: “[concat(variables(‘vmName’),’-osDisk’)]”, “osType”: “[parameters(‘osType’)]”,
“caching”: “ReadWrite”, “image”: {
“uri”: “[parameters(‘vhdUrl’)]”
},
“vhd”: {
“uri”: “[variables(‘osDiskVhdName’)]”
},
“createOption”: “FromImage”
}
}
For context, the following vhdUrl parameter and osDiskVhdName variable is shown:
“vhdUrl”: {
“type”: “string”, “metadata”: {
“description”: “VHD Url…”
}
}
“osDiskVhdName”: “[concat(‘http://’,parameters(‘userStorageAccountName’), ‘.blob.core.windows.net/’,parameters(‘userStorageContainerName’),’/’, parameters(‘vmName’),’osDisk.vhd’)]”
See the following for a complete template example: https://learn.microsoft.com/en-us/ partner-center/marketplace/azure-vm-image-test.