Azure 可用区 ARM 配置
Azure Availability Zone ARM Config
我正在尝试创建一个将 VM 部署到指定区域的 ARM 模板,但是我不断收到以下错误。不知道为什么,我上网查了一下,也跟着其他的例子,但还是卡住了。
区域模板代码
"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”超出范围。有点误导。经过我的验证。主要问题是在 dataDisks
属性 中使用“复制”。
当你将参数diskCount定义为2
时,你还应该在参数diskSize中定义2个匹配元素大批。此外,我将参数 zone 类型更改为 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]
}
}
}
我正在尝试创建一个将 VM 部署到指定区域的 ARM 模板,但是我不断收到以下错误。不知道为什么,我上网查了一下,也跟着其他的例子,但还是卡住了。
区域模板代码
"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”超出范围。有点误导。经过我的验证。主要问题是在 dataDisks
属性 中使用“复制”。
当你将参数diskCount定义为2
时,你还应该在参数diskSize中定义2个匹配元素大批。此外,我将参数 zone 类型更改为 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]
}
}
}