ArmExamples
ArmExamples copied to clipboard
Nested template inline with resource copy
There is a NestedTemplateInline.json template which can be used also for cross resource group deployments in your repo. It even has a copyIndex() usage example, but it uses property copy iteration.
I have a template in which I want to do cross resource group deployment and inside the inline template I moved resources that were deployed using resource iteration method (earlier they were in root template and deployment worked), but when I try to deploy it I get error message - "...Microsoft.Resources/deployments... The template function 'copyIndex' is not expected at this location. The function can only be used in a resource with copy specified." Is it a bug or by design? Because it looks like only property copy syntax is allowed in nested inline template. But I have some resources and a bunch of alerts configured inside the nested template, so I can't use property iteration syntax.
I've found another strange issue. ListKeys function also seems to not work in nested template. For example, Azure Function default template contains this code:
{
"name": "AzureWebJobsDashboard",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-05-01-preview').key1)]"
},
And it perfectly works in root a template, but in nested template I get an error: The Resource 'Microsoft.Storage/storageAccounts/somestorageaccount' under resource group 'RG' was not found. It looks like dependsOn defined on Function resource is ignored and listKeys tries to execute before storage account is created.
did you find an answer/workaround to this ?
Yeah, I stopped using nested inline templates.
Having the same problem myself.
This still seems to be an issue using even the latest API - 2018-05-01
I worked around the issue by looping outside of the nested template
Did you find any workaround to this? I have this piece of resource which I want to iterate couple of times The code below is part of the master template, I use the template link (citrix-connector-vm.json) which, actually creates a VM { "name": "[concat('CreateConnector',copyIndex(),uniqueString(resourceGroup().id))]", "type": "Microsoft.Resources/deployments", "apiVersion": "2017-05-10", "dependsOn": [ "[resourceId('Microsoft.Compute/availabilitySets', variables('connAvailailitySetName'))]" ], "properties": { "mode": "Incremental", "templateLink": { "uri": "[concat(uri(deployment().properties.templateLink.uri,'citrix-connector-vm.json'),parameters('SasToken'))]", "contentVersion": "1.0.0.0" }, "parameters": { "virtualNetworkName": { "value": "[parameters('virtualNetworkName')]" }, "adSubnetName": { "value": "[parameters('adSubnetName')]" }, "connAvailabilitySetName": { "value": "[variables('connAvailailitySetName')]" }, "connVmName": { "value": "[concat(variables('connVMName'), copyIndex())]" }, "connVmIp": { "value": "10.3.0.7" }, "connAdminUsername": { "value": "[parameters('connAdminUsername')]" }, "connAdminPassword": { "value": "[parameters('connAdminPassword')]" }, "connVmSize": { "value": "[parameters('connVmSize')]" }, "connDiskType": { "value": "[parameters('connDiskType')]" }, "connImageSKU": { "value": "[parameters('connImageSKU')]" } } }, "copy": { "name": "CopyConnectorVM", "count": "[parameters('numberOfConnectors')]", "mode": "Serial", "batchSize":1 } }
Sorry to bump up an older topic, but I can repro this issue with the copy function and nested templates as well.
Anything on this yet?