在 arm 模板中引用嵌套数组中的对象
Referencing an object in a nested array in an arm template
我正在尝试基于几个数组创建多个资源。这些资源之一是一些存储帐户。我在嵌套数组中有这些存储帐户的名称:
"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....
我以为我可以像这样迭代:
{
"apiVersion": "[variables('storageApiVersion')]",
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountArray')[0][copyIndex()]]",
"location": "[variables('computeLocation')]",
"copy": {
"name": "storageLoop0",
"count": "[variables('saCount0')]"
我将拥有几个这样的存储帐户资源,所有资源都有一个副本,因此名称将从 0,0 到 0,1 0,2 等,在下一个资源中,名称是:
"name": "[variables('storageAccountArray')[1][copyIndex()]]"
所以 1,0 1,1 1,2 等等
但是,当我尝试部署时收到此错误:
'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.
根据这样的问题:Access / process (nested) objects, arrays or JSON json一般可以这样求值。 arm 评估模板的方式是否阻止我这样做?
当我尝试将这些磁盘用作我的 VM 的 OS 磁盘时,这也循环创建许多 VM,我无法添加它们,因为我需要访问嵌套数组:
"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...
我也试过将嵌套数组拆分成多个,但是当我循环需要自己的存储帐户的 VM 时,我仍然需要增加一个数字,这似乎要求我不能创建 VM在循环中。
我还可以拆分资源以循环到嵌套模板中。我是否可以创建许多 "Microsoft.Resources/deployments" 资源,这些资源都指向同一个外部模板,然后每次传入不同的数字作为参数以增加数字?
有什么想法吗?谢谢你的时间
我认为您的数组语法有误,请在您的变量声明中尝试这样做:
"m": [
[ "a", "b", "c" ],
[ "1", "2", "3" ]
]
IOW,删除声明的 "uniqueStringArray0" 部分,即创建一个数组元素,该元素是字符串而不是数组,因此 [0][0] 无效但 [1][0] 无效.
我正在尝试基于几个数组创建多个资源。这些资源之一是一些存储帐户。我在嵌套数组中有这些存储帐户的名称:
"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....
我以为我可以像这样迭代:
{
"apiVersion": "[variables('storageApiVersion')]",
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountArray')[0][copyIndex()]]",
"location": "[variables('computeLocation')]",
"copy": {
"name": "storageLoop0",
"count": "[variables('saCount0')]"
我将拥有几个这样的存储帐户资源,所有资源都有一个副本,因此名称将从 0,0 到 0,1 0,2 等,在下一个资源中,名称是:
"name": "[variables('storageAccountArray')[1][copyIndex()]]"
所以 1,0 1,1 1,2 等等
但是,当我尝试部署时收到此错误:
'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.
根据这样的问题:Access / process (nested) objects, arrays or JSON json一般可以这样求值。 arm 评估模板的方式是否阻止我这样做?
当我尝试将这些磁盘用作我的 VM 的 OS 磁盘时,这也循环创建许多 VM,我无法添加它们,因为我需要访问嵌套数组:
"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...
我也试过将嵌套数组拆分成多个,但是当我循环需要自己的存储帐户的 VM 时,我仍然需要增加一个数字,这似乎要求我不能创建 VM在循环中。
我还可以拆分资源以循环到嵌套模板中。我是否可以创建许多 "Microsoft.Resources/deployments" 资源,这些资源都指向同一个外部模板,然后每次传入不同的数字作为参数以增加数字?
有什么想法吗?谢谢你的时间
我认为您的数组语法有误,请在您的变量声明中尝试这样做:
"m": [
[ "a", "b", "c" ],
[ "1", "2", "3" ]
]
IOW,删除声明的 "uniqueStringArray0" 部分,即创建一个数组元素,该元素是字符串而不是数组,因此 [0][0] 无效但 [1][0] 无效.