gpt4 book ai didi

json - Azure ARM copyIndex()

转载 作者:行者123 更新时间:2023-12-03 04:19:24 25 4
gpt4 key购买 nike

我正在尝试创建一个 ARM 模板,该模板将允许我部署可能需要也可能不需要额外数据磁盘的虚拟机。但是,当我测试我的模板时,出现以下错误。

奇怪的是,如果 vmDataDisk 参数的值为 0 或 1,则一切正常。如果该参数大于 1,我会收到以下错误。

例如,以下内容效果很好:vmDataDisk = 1 和 vmDataDiskSizesInGb = 30

但是,以下值会引发错误:vmDataDisk = 3、vmDataDiskSizesInGb = 10,20,30

参数元素 - ARM json

  "parameters": {
...
"vmDataDisks": {
"type": "int",
"defaultValue": 0,
"allowedValues": [
0,
1,
2,
3,
4,
5
],
"metadata": {
"description": "Select the number of data disks (in addition to OS disk) needed for this VM."
}
},
"vmDataDiskSizesInGb": {
"type": "string",
"defaultValue": 0,
"metadata": {
"description": "Enter string of comma separated values for the size of each data disk. For example, if the VmDataDisks parameter is set to '3', the VmDataDiskSizesInGb parameter might have a value of '10,25,50' and the template will deploy 3 data disks that are 10, 25 and 50 GB in size respectively."
}
}
}

变量元素 - ARM json

"variables": {
...
"diskSizes": "[split(parameters('vmDataDiskSizesInGb'), ',')]",
"copy": [
{
"name": "dataDisks",
"count": "[if(equals(parameters('vmDataDisks'),0), 1, parameters('vmDataDisks'))]",
"input": {
"name": "[concat(parameters('vmName'), '_DataDisk_', copyIndex('dataDisks'))]",
"lun": "[copyIndex('dataDisks')]",
"createOption": "Empty",
"diskSizeGB": "[if(equals(parameters('vmDataDisks'),0), 1, int(variables('diskSizes')[copyIndex()]))]",
"caching": "[if(startsWith(parameters('vmType'), 'SQL'), 'ReadOnly', 'None')]",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
}
}
]
}

资源元素 - ARM json

"resources": [
{
"type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('vmName')]",
"apiVersion": "2017-03-30",
"location": "[parameters('location')]",
"dependsOn": [],
"properties": {
"hardwareProfile": {},
"osProfile": {},
"storageProfile": {
"imageReference": {},
"osDisk": {},
"dataDisks": "[if(equals(parameters('vmDataDisks'),0), json('null'), variables('dataDisks'))]"
},
"networkProfile": {},
"diagnosticsProfile": {}
}
}
]

测试-AzureRmResourceGroup部署错误

Code : InvalidTemplate
Message : Deployment template language expression evaluation failed: 'The language expression property '0' can't be evaluated.'. Please see https://aka.ms/arm-template-expressions for usage details.
Details :

最佳答案

该错误表示无法评估您在模板中使用的语言表达式。也就是说,你使用的语言表达不符合模板的规则。错误的表达式属性是“0”。

因此,您应该检查所有属性为“0”的表达式,并与错误发布的文档进行比较:https://aka.ms/arm-template-expressions .

更新

在您发布的模板代码中,参数“vmDataDiskSizesInGb”类型是字符串,而您的“defaultValue”是0,这是不正确的,您应该给它“0”。

但是我不确定您是否还有其他错误,所以我建议您检查所有属性为“0”的表达式与错误发布的文档进行比较:https://aka.ms/arm-template-expressions .

关于json - Azure ARM copyIndex(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50496352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com