Reputation: 1279
I am trying to create several resources based off a few arrays. One of these resources is some storage accounts. I have the names of these storage accounts in a nested array:
"storageAccountArray": [
"uniqueStringArray0",
[
"[toLower(concat(parameters('prefix'), 'vhd0', variables('uniqueSuffixID'), '0'))]",
"[toLower(concat(parameters('prefix'), 'vhd0', variables('uniqueSuffixID'), '1'))]",
"[toLower(concat(parameters('prefix'), 'vhd0', variables('uniqueSuffixID'), '2'))]",
"[toLower(concat(parameters('prefix'), 'vhd0', variables('uniqueSuffixID'), '3'))]",
"[toLower(concat(parameters('prefix'), 'vhd0', variables('uniqueSuffixID'), '4'))]"
],
"uniqueStringArray1",
[
"[toLower(concat(parameters('prefix'), 'vhd1', variables('uniqueSuffixID'), '0'))]",
"[toLower(concat(parameters('prefix'), 'vhd1', variables('uniqueSuffixID'), '1'))]",
"[toLower(concat(parameters('prefix'), 'vhd1', variables('uniqueSuffixID'), '2'))]",
"[toLower(concat(parameters('prefix'), 'vhd1', variables('uniqueSuffixID'), '3'))]",
"[toLower(concat(parameters('prefix'), 'vhd1', variables('uniqueSuffixID'), '4'))]"
],
"uniqueStringArray2",
[
"[toLower(concat(parameters('prefix'), 'vhd2', variables('uniqueSuffixID'), '0'))]",
"[toLower(concat(parameters('prefix'), 'vhd2', variables('uniqueSuffixID'), '1'))]",
etc....
I thought I would be able to iterate through this like so:
{
"apiVersion": "[variables('storageApiVersion')]",
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountArray')[0][copyIndex()]]",
"location": "[variables('computeLocation')]",
"copy": {
"name": "storageLoop0",
"count": "[variables('saCount0')]"
Where I will have several of these storage account resources, all with a copy, so the name would get taken from 0,0 then 0,1 0,2 etc, and on the next resource the name is:
"name": "[variables('storageAccountArray')[1][copyIndex()]]"
So 1,0 1,1 1,2 etc.
However, when I attempt to deploy I receive this error:
'The template resource '[variables('storageAccountArray')[0][copyIndex()]]' is not valid: Template language expression property 'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Templates.Expressions.TemplateFunctionExpression' can't be evaluated.
According to questions like this: Access / process (nested) objects, arrays or JSON json can normally be evaluated this way. Does the way arm evaluates the template prevent me from doing this?
When I try to use these disks as OS disks for my VMs, which is also getting looped to create many VMs, I am unable to add them as I require accessing the nested array:
"osDisk": {
"vhdContainers": [
"[concat('https://', variables('storageAccountArray')[copyIndex()][0], '.blob.core.windows.net/', parameters('vmStorageAccountContainerNameType0'))]",
"[concat('https://', variables('storageAccountArray')[copyIndex()][1], '.blob.core.windows.net/', parameters('vmStorageAccountContainerNameType0'))]",
"[concat('https://', variables('storageAccountArray')[copyIndex()][2], '.blob.core.windows.net/', parameters('vmStorageAccountContainerNameType0'))]",
etc...
I also tried splitting the nested array into many, but as I am looping the VM that requires its own storage accounts, I would still need to increment one number, which seems that it would demand that I cannot create the VM in a loop.
I could also split the resource to loop into a nested template. Would I be able to create many "Microsoft.Resources/deployments" resources that all point to the same external template, then pass in a different number each time as a parameter to increment the number that way?
Any ideas? Thank you for your time
Upvotes: 0
Views: 3645
Reputation: 8737
I think your array syntax is wrong, try this in your variable declaration:
"m": [
[ "a", "b", "c" ],
[ "1", "2", "3" ]
]
IOW, remove your "uniqueStringArray0" part of your declaration, that's creating an array element which is a string and not an array so [0][0] is invalid but [1][0] is not.
Upvotes: 1