Using copy with deployment resources

The copy object can be used to iterate over the deployment resource type as well as create multiple deployments. The deployment is linked to another ARM template, and, as a result, the linked ARM templates is called multiple times and it provisions multiple resources.

It is important to understand that when a deployment resource is executed, it creates a separate deployment rather than provisioning resources within the same deployment.

For executing multiple subdeployments using ARM templates, we need a linked template, and we will use the template shown in the following code block. The entire code for this ARM template is available with the chapter-accompanied code file: chapter-4 - listing8.txt. It is the same template that we have used in the last two sections.

This template should be uploaded to a storage account, and the URL of that template should be used in the deployment resource. The name of the storage account used in this example is myarmtemplates, and the name of the linked ARM template is chapter-4 - listing8.txt. A copy object is added to the resource definition that loops twice, and the copyindex function in the resource name property ensures that we do not have multiple resource instances with the same name. Note that there is no copy object within the linked template, where the storage resource is defined. The entire code for this ARM template is available with the chapter-accompanied code file: chapter-4 - listing9.txt:

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountName": {
"type": "string",
"minLength": 5
}
},
"resources": [
{
"apiVersion": "2017-05-10",
"name": "[concat('nestedTemplate', copyindex())]",
"type": "Microsoft.Resources/deployments",
"copy": {
"name": "looping",
"count": 2
},
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "https://myarmtemplates.blob.core.windows.net/temps/chapter-4 - listing8.json",
"contentVersion": "1.0.0.0"
},
"parameters": {
"storageAccountName": { "value": "[parameters('storageAccountName')]" }
}
}
}
]}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.103.183