Я довольно новичок в использовании шаблонов azure для развертываний и работал над тем, который развертывает набор виртуальных машин. На первой итерации шаблона я настроил его на чтение файла параметров и указал имя виртуальной машины в качестве параметра - этот параметр использовался для формирования имени NI C, а также имени диска ОС.
Сейчас я пытаюсь настроить шаблон для создания нескольких виртуальных машин на основе массива в параметрах.
Я установил параметр
"virtualMachineName": {
"type": "array",
"defaultValue": [
"VM-WEB01",
"VM-WEB02"
]
, а затем в файле шаблона, на который я ссылался, похож на этот
"networkInterfaceName": "[concat(toUpper(parameters('virtualMachineName')[copyIndex()]),'-NIC')]"
"name": "[concat(parameters('virtualMachineName')[copyIndex()],'-osDisk')]",
et c.
Затем я использовал опцию копирования в конце раздела ресурсов, но перед разделом выходных данных в шаблоне
"copy": {
"name": "vmcopy",
"count": "[length(parameters('virtualMachineName'))]"
}
при попытке развернуть шаблон я получаю сообщение об ошибке: Параметр virtualMachineName имеет значение null.
Любые указатели, где я иду не так, будут оценены.
это полный шаблон
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"networkSecurityGroupName": {
"type": "string"
},
"networkSecurityGroupRules": {
"type": "array"
},
"subnetName": {
"type": "string"
},
"virtualNetworkId": {
"type": "string"
},
"virtualMachineName": {
"type": "array",
"defaultValue": [
"PROD-VM-RDGW01",
"PROD-VM-RDGW02"
]
},
"virtualMachineRG": {
"type": "array"
},
"osDiskType": {
"type": "string"
},
"virtualMachineSize": {
"type": "string"
},
"adminUsername": {
"type": "string"
},
"adminPassword": {
"type": "securestring"
},
"diagnosticsStorageAccountName": {
"type": "string"
},
"diagnosticsStorageAccountId": {
"type": "string"
},
"availabilitySetName": {
"type": "string"
},
"availabilitySetPlatformFaultDomainCount": {
"type": "int"
},
"availabilitySetPlatformUpdateDomainCount": {
"type": "int"
},
"backupVaultName": {
"type": "string"
},
"backupFabricName": {
"type": "string"
},
"backupVaultRGName": {
"type": "string"
},
"backupVaultRGIsNew": {
"type": "bool"
},
"backupPolicyName": {
"type": "string"
},
"backupItemName": {
"type": "string"
}
},
"variables": {
"networkInterfaceName": "[concat(toUpper(parameters('virtualMachineName')[copyIndex()]),'-NIC')]",
"nsgId": "[resourceId(resourceGroup().name, 'Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]",
"vnetId": "[parameters('virtualNetworkId')]",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]"
},
"resources": [
{
"name": "[variables('networkInterfaceName')]",
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2019-07-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateIPAllocationMethod": "Dynamic"
}
}
],
"networkSecurityGroup": {
"id": "[variables('nsgId')]"
}
},
"tags": {
"billTO": "IT",
"Environment": "Production",
"projectName": "RDS"
},
"copy": {
"name": "vmNICCopy",
"count": "[length(parameters('virtualMachineName'))]"
}
},
{
"name": "[parameters('networkSecurityGroupName')]",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2019-02-01",
"location": "[parameters('location')]",
"properties": {
"securityRules": "[parameters('networkSecurityGroupRules')]"
},
"tags": {
"billTO": "IT",
"Environment": "Production",
"projectName": "RDS"
}
},
{
"name": "[concat(parameters('virtualMachineName')[copyIndex())]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2019-07-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', variables('networkInterfaceName'))]",
"[concat('Microsoft.Compute/availabilitySets/', parameters('availabilitySetName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"storageProfile": {
"osDisk": {
"createOption": "fromImage",
"name": "[concat(parameters('virtualMachineName')[copyIndex()],'-osDisk')]",
"managedDisk": {
"storageAccountType": "[parameters('osDiskType')]"
}
},
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
}
]
},
"osProfile": {
"computerName": "[concat(parameters('virtualMachineName')[copyIndex())]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]",
"windowsConfiguration": {
"enableAutomaticUpdates": true,
"provisionVmAgent": true
}
},
"licenseType": "Windows_Server",
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[concat('https://', parameters('diagnosticsStorageAccountName'), '.blob.core.windows.net/')]"
}
},
"availabilitySet": {
"id": "[resourceId('Microsoft.Compute/availabilitySets', parameters('availabilitySetName'))]"
}
},
"tags": {
"billTO": "IT",
"Environment": "Production",
"projectName": "RDS"
},
"copy": {
"name": "vmCopy",
"count": "[length(parameters('virtualMachineName'))]"
}
},
{
"name": "[parameters('availabilitySetName')]",
"type": "Microsoft.Compute/availabilitySets",
"apiVersion": "2019-07-01",
"location": "[parameters('location')]",
"properties": {
"platformFaultDomainCount": "[parameters('availabilitySetPlatformFaultDomainCount')]",
"platformUpdateDomainCount": "[parameters('availabilitySetPlatformUpdateDomainCount')]"
},
"sku": {
"name": "Aligned"
},
"tags": {
"billTO": "IT",
"Environment": "Production",
"projectName": "RDS"
}
},
{
"apiVersion": "2017-05-10",
"name": "[concat(parameters('virtualMachineName')[copyIndex()], '-' , 'BackupIntent')]",
"type": "Microsoft.Resources/deployments",
"resourceGroup": "[parameters('backupVaultRGName')]",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"name": "[concat(parameters('backupVaultName'), '/', parameters('backupFabricName'), '/', parameters('backupItemName'))]",
"apiVersion": "2017-07-01",
"type": "Microsoft.RecoveryServices/vaults/backupFabrics/backupProtectionIntent",
"properties": {
"friendlyName": "[concat(parameters('virtualMachineName')[copyIndex()], 'BackupIntent')]",
"protectionIntentItemType": "AzureResourceItem",
"policyId": "[resourceId(parameters('backupVaultRGName'), 'Microsoft.RecoveryServices/vaults/backupPolicies', parameters('backupVaultName'), parameters('backupPolicyName'))]",
"sourceResourceId": "[resourceId(parameters('virtualMachineRG'), 'Microsoft.Compute/virtualMachines', parameters('virtualMachineName')[copyIndex()])]"
}
}
]
},
"copy": {
"name": "vmNICCopy",
"count": "[length(parameters('virtualMachineName'))]"
}
},
"dependsOn": [
"[resourceId(parameters('virtualMachineRG'), 'Microsoft.Compute/virtualMachines', [concat(parameters('virtualMachineName')[copyIndex())])]]"
]
}
],
"outputs": {
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
}
}
}