Azure可用性区域ARM配置



我正试图创建一个ARM模板,将VM部署到指定的区域,但我一直收到以下错误。不知道为什么,我在网上查了一下,并遵循了其他的例子,但仍然停滞不前。

区域模板的代码

"zone": {
"type": "string",
"defaultValue": "1",
"allowedValues": [
"1",
"2",
"3"
],
"metadata": {
"description": "Zone number for the virtual machine"
}
},

参数文件为:

"zone": {
"value": "2"
},

但我得到的错误是:

New-AzResourceGroupDeployment : 10:11:08 - Error: Code=InvalidTemplate; Message=Deployment template parse failed: 'Error converting value "2" to type 'System.String[]'. 
Path ''.'.
At line:7 char:1

有人能给我指正确的方向吗。我尝试过将区域用作数组和整数,但似乎都不起作用。

提前感谢:(

############编辑参数文件

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"value": "vm2002"
},
"adminUsername": {
"value": "localadmin"
},
"adminPasswordOrKey": {
"value": "P@ssword1234"
},
"ubuntuOSVersion": {
"value": "18.04-LTS"
},
"VmSize": {
"value": "Standard_d2-v4"
},
"networkName": {
"value": "tt-vnet"
},
"networkResourceGroup": {
"value": "deployrg3"
},
"subnetName": {
"value": "tt-sub1"
},
"zone": {
"value": [
"2"
]
},
"diskCount": {
"value": 2
},
"diskSize": {
"value": [
"32"
]
}
}
}

模板文件

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string",
"defaultValue": "linuxvm",
"metadata": {
"description": "The name of you Virtual Machine."
}
},
"adminUsername": {
"type": "string",
"metadata": {
"description": "Username for the Virtual Machine."
}
},
"authenticationType": {
"type": "string",
"defaultValue": "password",
"allowedValues": [
"sshPublicKey",
"password"
],
"metadata": {
"description": "Type of authentication to use on the Virtual Machine. SSH key is recommended."
}
},
"adminPasswordOrKey": {
"type": "securestring",
"metadata": {
"description": "SSH Key or password for the Virtual Machine. SSH key is recommended."
}
},
"ubuntuOSVersion": {
"type": "string",
"defaultValue": "18.04-LTS",
"allowedValues": [
"12.04.5-LTS",
"14.04.5-LTS",
"16.04.0-LTS",
"18.04-LTS"
],
"metadata": {
"description": "The Ubuntu version for the VM. This will pick a fully patched image of this given Ubuntu version."
}
},
"VmSize": {
"type": "string",
"defaultValue": "Standard_B2s",
"metadata": {
"description": "The size of the VM"
}
},
"networkName": {
"type": "string",
"minLength": 1
},
"networkResourceGroup": {
"type": "string",
"minLength": 1
},
"subnetName": {
"type": "string",
"minLength": 1
},
"zone": {
"type": "array"
"defaultValue": "1",
"allowedValues": [
"1",
"2",
"3"
],
"metadata": {
"description": "Zone number for the virtual machine"
}
},
"diskCount": {
"type": "int",
"defaultValue": 1
},
"diskSize": {
"type": "array"
}
},
"variables": {
"cnt": "[Parameters('diskCount')]",
"osDiskType": "Premium_LRS",
"VNetID": "[resourceId(Parameters('networkResourceGroup'), 'Microsoft.Network/virtualNetworks', Parameters('networkname'))]",
"SubnetRef": "[concat(variables('VNetID'), '/subnets/', Parameters('subnetName'))]",
"networkInterfaceName": "[concat(Parameters('VMName'), '-nic1')]",
"linuxConfiguration": {
"disablePasswordAuthentication": true,
"ssh": {
"publicKeys": [
{
"path": "[concat('/home/', parameters('adminUsername'), '/.ssh/authorized_keys')]",
"keyData": "[parameters('adminPasswordOrKey')]"
}
]
}
}
},
"resources": [
{
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2020-05-01",
"name": "[variables('networkInterfaceName')]",
"location": "[resourceGroup().location]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateIPAllocationMethod": "Dynamic"
}
}
]
}
},
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2020-06-01",
"name": "[parameters('vmName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[variables('networkInterfaceName')]"
],
"zones": "[parameters('zone')]",
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('VmSize')]"
},
"storageProfile": {
"osDisk": {
"createOption": "fromImage",
"managedDisk": {
"storageAccountType": "[variables('osDiskType')]"
},
"copy": [
{
"name": "datadisks",
"count": "[variables('cnt')]",
"input": {
"name": "[concat(Parameters('VMName'), '-dataDisk', add(copyIndex('datadisks'), 1))]",
"createOption": "Empty",
"diskSizeGB": "[Parameters('diskSize')[copyIndex('datadisks')]]",
"caching": "None",
"lun": "[copyIndex('datadisks')]"
}
}
]
},
"imageReference": {
"publisher": "Canonical",
"offer": "UbuntuServer",
"sku": "[parameters('ubuntuOSVersion')]",
"version": "latest"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
}
]
},
"osProfile": {
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPasswordOrKey')]",
"linuxConfiguration": "[if(equals(parameters('authenticationType'), 'password'), json('null'), variables('linuxConfiguration'))]"
}
}
}
],
"outputs": {
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
}
}
}

错误消息语言表达式属性数组索引"1"越界有点误导人。经过我的验证。主要问题是使用";复制";在CCD_ 1属性中。

当您将参数diskCount数字定义为2时,还应在参数diskSize数组中定义2个匹配元素。此外,我更改为将参数区域类型定义为string类型。

这是工作样本:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string",
"defaultValue": "linuxvm",
"metadata": {
"description": "The name of you Virtual Machine."
}
},
"adminUsername": {
"type": "string",
"metadata": {
"description": "Username for the Virtual Machine."
}
},
"authenticationType": {
"type": "string",
"defaultValue": "password",
"allowedValues": [
"sshPublicKey",
"password"
],
"metadata": {
"description": "Type of authentication to use on the Virtual Machine. SSH key is recommended."
}
},
"adminPasswordOrKey": {
"type": "securestring",
"metadata": {
"description": "SSH Key or password for the Virtual Machine. SSH key is recommended."
}
},
"ubuntuOSVersion": {
"type": "string",
"defaultValue": "18.04-LTS",
"allowedValues": [
"12.04.5-LTS",
"14.04.5-LTS",
"16.04.0-LTS",
"18.04-LTS"
],
"metadata": {
"description": "The Ubuntu version for the VM. This will pick a fully patched image of this given Ubuntu version."
}
},
"VmSize": {
"type": "string",
"defaultValue": "Standard_B2s",
"metadata": {
"description": "The size of the VM"
}
},
"networkName": {
"type": "string",
"minLength": 1
},
"networkResourceGroup": {
"type": "string",
"minLength": 1
},
"subnetName": {
"type": "string",
"minLength": 1
},
"zone": {
"type": "string",
"defaultValue": "1",
"allowedValues": [
"1",
"2",
"3"
],
"metadata": {
"description": "Zone number for the virtual machine"
}
}
,
"diskCount": {
"type": "int",
"defaultValue": 1
},
"diskSize": {
"type": "array"
}
},
"variables": {
"cnt": "[Parameters('diskCount')]",
"osDiskType": "Premium_LRS",
"VNetID": "[resourceId(Parameters('networkResourceGroup'), 'Microsoft.Network/virtualNetworks', Parameters('networkname'))]",
"SubnetRef": "[concat(variables('VNetID'), '/subnets/', Parameters('subnetName'))]",
"networkInterfaceName": "[concat(Parameters('VMName'), '-nic1')]",
"linuxConfiguration": {
"disablePasswordAuthentication": true,
"ssh": {
"publicKeys": [
{
"path": "[concat('/home/', parameters('adminUsername'), '/.ssh/authorized_keys')]",
"keyData": "[parameters('adminPasswordOrKey')]"
}
]
}
}
},
"resources": [
{
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2020-05-01",
"name": "[variables('networkInterfaceName')]",
"location": "[resourceGroup().location]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateIPAllocationMethod": "Dynamic"
}
}
]
}
},
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2020-06-01",
"name": "[parameters('vmName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[variables('networkInterfaceName')]"
],
"zones": [
"[parameters('zone')]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('VmSize')]"
},
"storageProfile": {
"imageReference": {
"publisher": "Canonical",
"offer": "UbuntuServer",
"sku": "[parameters('ubuntuOSVersion')]",
"version": "latest"
},
"osDisk": {
"createOption": "fromImage",
"managedDisk": {
"storageAccountType": "[variables('osDiskType')]"
}
},
"copy": [
{
"name": "dataDisks",
"count": "[variables('cnt')]",
"input": {
"name": "[concat(Parameters('VMName'), '-dataDisk', add(copyIndex('dataDisks'), 1))]",
"createOption": "Empty",
"diskSizeGB": "[Parameters('diskSize')[copyIndex('dataDisks')]]",
"caching": "None",
"lun": "[copyIndex('dataDisks')]"
}
}
]
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
}
]
},
"osProfile": {
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPasswordOrKey')]",
"linuxConfiguration": "[if(equals(parameters('authenticationType'), 'password'), json('null'), variables('linuxConfiguration'))]"
}
}
}
],
"outputs": {
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
}
}
}

参数:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"value": "vm2002"
},
"adminUsername": {
"value": "localadmin"
},
"adminPasswordOrKey": {
"value": "Password"
},
"ubuntuOSVersion": {
"value": "18.04-LTS"
},
//   "VmSize": {
//     "value": "Standard_B1s"
//   },
"networkName": {
"value": "vvvv"
},
"networkResourceGroup": {
"value": "nancyarm"
},
"subnetName": {
"value": "default"
},
"zone": {
"value": "2"      
},
"diskCount": {
"value": 2
},
"diskSize": {
"value": [32,64]
}
}
}

最新更新