I am going to use this answer to use the link to my research on nested templates.
Looking at here I see an approach that would have two nested patterns, for example:
"resources": [ { "name": "MultiDataDisk", "type": "Microsoft.Compute/virtualMachines", "apiVersion": "2016-04-30-preview", "location": "[parameters('rgLocation')]", "dependsOn": [ "[concat('Microsoft.Storage/storageAccounts/', parameters('rgStorageAccountName'))]" ], "properties": { "osProfile": { ... }, "hardwareProfile": { ... }, "storageProfile": { "imageReference": { ... }, "osDisk": { ... }, "copy": [ { "name": "dataDisks", "count": "[length(parameters('VirtualMachineDiskSizeArray'))]", "input": { "lun": "[copyIndex('dataDisks')]", "name": "[concat(parameters('vmDataDiskNameStub'), add(copyIndex('dataDisks'),1), '.vhd')]", "diskSizeGB": "[parameters('VirtualMachineDiskSizeArray')[copyIndex('dataDisks')]]", "createOption": "Empty", "vhd": { "uri": "[concat(concat(reference(resourceId(parameters('rgName'), 'Microsoft.Storage/storageAccounts', parameters('rgStorageAccountName')), '2015-06-15').primaryEndpoints['blob'], 'vhds/'), concat(parameters('vmDataDiskNameStub'), add(copyIndex('dataDisks'),1), '.vhd') )]" } } } ] } } } ]
and one such:
"resources": [ { "name": "ZeroDataDisk", "type": "Microsoft.Compute/virtualMachines", "apiVersion": "2016-04-30-preview", "location": "[parameters('rgLocation')]", "dependsOn": [ "[concat('Microsoft.Storage/storageAccounts/', parameters('rgStorageAccountName'))]" ], "properties": { "osProfile": { ... }, "hardwareProfile": { ... }, "storageProfile": { "imageReference": { ... }, "osDisk": { ... }, "dataDisks": [] } } } ]
And refer to them from the parent template:
"parameters": { "nestedType": { "type": "string", "defaultValue": "ZeroDataDisk", "allowedValues": [ "ZeroDataDisk", "MultiDataDisk" ], } }, "resources": [ { "name": "[concat("nested-",parameters('virtualMachineName')]", "type": "Microsoft.Resources/deployments", "apiVersion": "2015-01-01", "properties": { "mode": "Incremental", "templateLink": { "uri": "[concat('https://someplace.on.the.internet/nested/',parameter('nestedType'),".json")], "contentVersion": "1.0.0.0" }, "parameters": { "rgStorageAccountName": { "value": "[parameters(rgStorageAccountName)]" }, "OtherParms": { "value": "[parameters('otherParms')]" } . . . } } ] }
However, I don’t think it’s better / easier than what I did in response to the “interest of the time”, because
- The section that interests me (dataDisks) is surrounded by a bunch of other json that does not change me, leaving me with the same crappy problem that you need to manually synchronize the code between two files.
- Now I have to not only support two json files for the embedded resources, but I have to publish them through the public URL.
Basically, if I can’t get a copy of the 0-N section (and not 1-N) or only attach the section, my two files using the powershell switch seem to be the least overhead.