我有一个VM部署模板,其中我将VM大小定义为T恤大小,例如small = Standard_DS2_v2,medium = Standard_E4s_v3和large = Standard_E4s_v3。
我已将它们定义为数组,如下面的变量部分
所示 "parameters": {
"vmSpecs": {
"type": "array"
}
},
"variables": {
"vmSizeType" :[{
"small" : "Standard_DS2_v2",
"medium": "Standard_E4s_v3",
"large" : "Standard_E32s_v3"
}]
},
"resources": [
{
"name": "[parameters('vmSpecs')[copyIndex()].vmName]",
"type": "Microsoft.Compute/virtualMachines",
"location": "[resourceGroup().location]",
"apiVersion": "2018-06-01",
"dependsOn": [
"VMNIC0Copy",
"[variables('storageAccountName')]"
],
"copy": {
"name": "VMCopy",
"count": "[length(parameters('vmSpecs'))]"
},
"properties": {
"licenseType": "[parameters('vmSpecs')[copyIndex()].licenseType]",
"hardwareProfile": {
"vmSize": "[parameters('vmSpecs')variables('vmSizeType')[copyIndex()].vmSize[1]]"
}
}
在参数文件中
"vmSpecs": {
"value": [
{ //vm01
"vmName": "test",
"dnsDomain": "domain.com",
"vmSize": "medium"
}
}
我的问题是如何输入vmSize并根据定义的大小选择大小
答案 0 :(得分:1)
像通常那样(使用点符号)访问几乎任何语言的对象属性:
"vmSizeType" :{ << should be an object, you only make it harder making it an array
"small" : "Standard_DS2_v2",
"medium": "Standard_E4s_v3",
"large" : "Standard_E32s_v3"
}
...
"vmSize": "[variables('vmSizeType')[parameters('vmSpecs')[copyIndex()].vmSize]]"
^^ tshirt variable ^ ^^ input parameter ^^ iteration ^^ property
^ get property defined dynamically, have to use [] syntax instead of dot notation
for static\hardcoded property name you can use dot notation:
variables('vmSizeType').small
如果您需要将tshirt变量设置为数组(没有理由),则也必须考虑到这一点