ArmExamples icon indicating copy to clipboard operation
ArmExamples copied to clipboard

Nested template inline with resource copy

Open KacperMucha opened this issue 7 years ago • 9 comments

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.

KacperMucha avatar Oct 05 '17 22:10 KacperMucha

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.

KacperMucha avatar Oct 09 '17 16:10 KacperMucha

did you find an answer/workaround to this ?

abhi1509 avatar Feb 02 '18 03:02 abhi1509

Yeah, I stopped using nested inline templates.

KacperMucha avatar Mar 25 '18 18:03 KacperMucha

Having the same problem myself.

wahidsaleemi avatar Mar 28 '18 20:03 wahidsaleemi

This still seems to be an issue using even the latest API - 2018-05-01

rkuehfus avatar Sep 16 '18 19:09 rkuehfus

I worked around the issue by looping outside of the nested template

tyconsulting avatar Mar 05 '19 00:03 tyconsulting

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 } }

tapasudenia avatar Mar 28 '19 15:03 tapasudenia

Sorry to bump up an older topic, but I can repro this issue with the copy function and nested templates as well.

JackStromberg avatar Aug 29 '19 09:08 JackStromberg

Anything on this yet?

hsubramaniam avatar Sep 16 '19 13:09 hsubramaniam