用于创建虚拟机的 Bicep 代码因磁盘创建“dataDisk.managementDisk.id”而失败

问题描述 投票:0回答:1

我正在使用二头肌创建虚拟机,但是在创建磁盘时收到错误消息。该代码最初是一个 ARM 模板,我将其转换为二头肌并部分重写了一些。

我收到以下错误。

{"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.","details":[{"code":"BadRequest","message":"{\r\n  \"error\": {\r\n    \"code\": \"InvalidParameter\",\r\n    \"message\": \"Required parameter 'dataDisk.managedDisk.id' is missing (null).\",\r\n    \"target\": \"dataDisk.managedDisk.id\"\r\n  }\r\n}"}]}}

要部署,我运行以下命令

az 部署组 create --resource-group 'rg_name' --template-file 。 m.bicep——参数。 m_parameters.json

param resGroup object
param vmconfig object
param vmnetworkconfig object
param keyvault object


// @description('The admin user name of the VM')
param adminUsername string = 'Anadministrator'

// @description('The admin password of the VM')
// @secure()
param adminPassword string = 'fgf893434Fd!324ff'

@description('Location for all resources.')
param location string = resourceGroup().location

var networkInterfaceName = '${vmconfig.virtualMachineName}-nic'
var networkSecurityGroupName = '${vmconfig.virtualMachineName}-nsg'
var networkSecurityGroupRules = [
  {
    name: 'RDP'
    properties: {
      priority: 300
      protocol: 'Tcp'
      access: 'Allow'
      direction: 'Inbound'
      sourceAddressPrefix: '*'
      sourcePortRange: '*'
      destinationAddressPrefix: '*'
      destinationPortRange: '3389'
    }
  }
]
var publicIpAddressName = '${vmconfig.virtualMachineName}-publicip-${uniqueString(vmconfig.virtualMachineName)}'
var publicIpAddressType = 'Dynamic'
var publicIpAddressSku = 'Basic'
// var nsgId = networkSecurityGroup.id
var subnetRef = resourceId(vmnetworkconfig.vnet_rg, 'Microsoft.Network/virtualNetWorks/subnets', vmnetworkconfig.vnet, vmnetworkconfig.vnet_subnet)


resource networkInterface 'Microsoft.Network/networkInterfaces@2022-01-01' = {
  name: networkInterfaceName
  location: location
  properties: {
    ipConfigurations: [
      {
        name: 'ipconfig1'
        properties: {
          subnet: {
            id: subnetRef
          }
          privateIPAllocationMethod: 'Dynamic'
          // publicIPAddress: {
          //   id: publicIpAddress.id
          // }
        }
      }
    ]
    enableAcceleratedNetworking: true
  }
}

resource sharedDisk 'Microsoft.Compute/disks@2022-03-02' = [for i in range(0, 1): {
  location: location
  name: '${vmconfig.virtualMachineName}-data${i}'

  properties: {
    creationData: {
      createOption: 'Empty'
    }
    diskSizeGB: 127
    osType: 'Windows'
  }
  sku: {
    name: 'StandardSSD_LRS'
  }
}]



resource virtualMachine 'Microsoft.Compute/virtualMachines@2022-03-01' = {
  name: vmconfig.virtualMachineName
  location: resourceGroup().location
  properties: {
    hardwareProfile: {
      vmSize: vmconfig.vmsize
    }
    storageProfile: {
      // osDisk: {
      //   createOption: 'FromImage'
      //   managedDisk: {
      //     storageAccountType: vmconfig.storageAccountType
      //   }
      // }
      osDisk: {
        osType: 'Windows'
        name: '${vmconfig.virtualMachineName}_OsDisk_1_6c072ce0998d4962b35be6f9ed02723e'
        createOption: 'FromImage'
        caching: 'ReadWrite'
        managedDisk: {
          storageAccountType: 'StandardSSD_LRS'
          // id: disks_vmcommvault02_OsDisk_1_6c072ce0998d4962b35be6f9ed02723e_externalid
        }
        deleteOption: 'Detach'
        diskSizeGB: 127
      }
      imageReference: {
        publisher: vmconfig.publisher
        offer:  vmconfig.offer
        sku: vmconfig.OSVersion
        version: vmconfig.version
      }
      dataDisks: [
        {
          lun: 0
          name: '${vmconfig.virtualMachineName}_DataDisk_0'
          createOption: 'Attach'
          caching: 'ReadOnly'
          managedDisk: {
            storageAccountType: 'Premium_LRS'
            // id: disks_vmcommvault02_DataDisk_0_externalid
          }
          deleteOption: 'Detach'
          diskSizeGB: 128
          toBeDetached: false
        }
      ]
      // diskControllerType: 'SCSI'
    }
    networkProfile: {
      networkInterfaces: [
        {
          id: networkInterface.id
        }
      ]
    }
    osProfile: {
      computerName: vmconfig.virtualMachineName
      adminUsername: adminUsername
      adminPassword: adminPassword
      windowsConfiguration: {
        enableAutomaticUpdates: true
        provisionVMAgent: true        
    }
    // patchSettings: {
    //   patchMode: 'AutomaticByOS'
    //   assessmentMode: 'ImageDefault'
    // }

  }
}
}

resource virtualMachines_vmcommvault02_name_BackupGateway 'Microsoft.Compute/virtualMachines/extensions@2023-03-01' = {
  parent: virtualMachine
  name: 'BackupGateway'
  location: resourceGroup().location
  properties: {
    autoUpgradeMinorVersion: true
    publisher: 'Microsoft.Compute'
    type: 'CustomScriptExtension'
    typeHandlerVersion: '1.7'
    settings: {
      fileUris: [
        'https://turindownloadcenter.blob.core.windows.net/m00/installpackage.ps1'
      ]
      commandToExecute: 'powershell -ExecutionPolicy Unrestricted -File installpackage.ps1 -packagedownloaduri https://turindownloadcenter.blob.core.windows.net/m00/AzureDBServer64.exe -companyauthcode 5D8DEEAE1'
    }
    protectedSettings: {
    }
  }
}

参数文件

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {  
        "resGroup": {
            "value": {
                "name": "RG-name",
                "tags": {
                    "Environment": "production"
                }
            }
        },
        "vmconfig": {
            "value": {
                "virtualMachineName": "vm45454546",
                "OSVersion": "2019-datacenter-smalldisk-g2",
                "vmsize": "Standard_D2s_v4",
                "publisher": "MicrosoftWindowsServer",
                "offer": "WindowsServer",  
                "sku": "2016-datacenter-gensecond",                
                "version": "latest",
                "storageAccountType": "StandardSSD_LRS",
                "diskSizeGB": "128"    

            }
        },

        "vmnetworkconfig": {
            "value":{
                "vnet": "vnet-general-euw-test",
                "vnet_subnet": "snet-compute-euw-perfsec",
                "vnet_rg": "rg-networks-euw-dev"
            } 
            
        },
        "keyvault": {
            "value":{
                "name": "kv-vm566"
            } 
            
        }

    }
}
azure-resource-manager azure-virtual-machine azure-bicep
1个回答
0
投票

您需要指定要附加到虚拟机的数据磁盘的

id
(请参阅文档)。
因为您使用循环来创建数据磁盘,所以这应该可以工作:

dataDisks: [for i in range(0, 1): {
  lun: i
  name: '${vmconfig.virtualMachineName}_DataDisk_${i}'
  createOption: 'Attach'
  caching: 'ReadOnly'
  managedDisk: {
    storageAccountType: 'Premium_LRS'
    id: sharedDisk[i].id
  }
  deleteOption: 'Detach'
  diskSizeGB: 128
  toBeDetached: false
}]
© www.soinside.com 2019 - 2024. All rights reserved.