部署 VM 时出现 bicep 错误 如果 VM 是从平台、用户或共享库映像创建的,则无法附加现有操作系统磁盘

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

我正在尝试从另一个模块创建的现有操作系统磁盘映像创建虚拟机。我收到以下错误

Cannot attach an existing OS disk if the VM is created from a platform, user or a shared gallery image. (Code: InvalidParameter, Target: osDisk)

代码来自反编译的arm模板,我可以看到它缺少本地登录密码。在这个阶段,我正在尝试让它构建一个虚拟机。我做了一些研究广告发现一个用户有类似的问题here,但是代码/解决方案不完整,因此我无法遵循它。

@description('The virtual machine parameter object.')
param vm object

@description('The tagging object.')
param tagging object

@description('The Network security rules ID')
param nsg_id string

@description('The Network interface card ID')
param nic_id string

@description('The managed disk ID')
param os_disk_id string


resource virtualMachines_azsdevinf001_name_resource 'Microsoft.Compute/virtualMachines@2023-03-01' = {
  name: vm.vm_name
  location: vm.location
  tags: tagging.tags
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    hardwareProfile: {
      vmSize: vm.vmSize
    }
    storageProfile: {
      imageReference: {
        publisher: 'MicrosoftWindowsServer'
        offer: 'WindowsServer'
        sku: vm.sku
        version: 'latest'
      }
      osDisk: {
        osType: vm.osType
        name: '${vm.vm_name}-osdisk'
        createOption: 'Attach'
        caching: 'ReadWrite'
        writeAcceleratorEnabled: false
        managedDisk: {
          id: os_disk_id
          storageAccountType: 'StandardSSD_LRS'
        }
        deleteOption: 'Detach'
      }
      dataDisks: []
    }
    
    osProfile: {
      computerName: vm.vm_name
      adminUsername: 'localadministrator'
      windowsConfiguration: {
        provisionVMAgent: true
        enableAutomaticUpdates: true
        patchSettings: {
          patchMode: 'AutomaticByPlatform'
          automaticByPlatformSettings: {
            bypassPlatformSafetyChecksOnUserSchedule: true
          }
          assessmentMode: 'AutomaticByPlatform'
          enableHotpatching: false
        }
        timeZone: 'GMT Standard Time'
        winRM: {
          listeners: []
        }
        enableVMAgentPlatformUpdates: false
      }
      secrets: []
      allowExtensionOperations: true
      requireGuestProvisionSignal: true
    }
    networkProfile: {
      networkInterfaces: [
        {
          id: nic_id
          properties: {
            primary: true
          }
        }
      ]
    }
    diagnosticsProfile: {
      bootDiagnostics: {
        enabled: true
        storageUri: 'xxxx'
      }
    }
    licenseType: 'Windows_Server'
    priority: 'Regular'
    extensionsTimeBudget: 'PT1H30M'
  }
}
azure-bicep
1个回答
0
投票

部署 VM 如果 VM 是使用 Bicep 从平台、用户或共享库映像创建的,则无法附加现有操作系统磁盘

当您的 Bicep 模板尝试指定图像引用并将现有操作系统磁盘同时附加到同一虚拟机时,通常会出现“如果虚拟机是从平台、用户或共享库映像创建,则无法附加现有操作系统磁盘”错误。但是,这些操作不能一起执行,因为它们是互斥的。

要使用现有操作系统磁盘创建虚拟机,请修改 Bicep 模板中的

storageProfile
以省略
imageReference
,同时将
createOption
osDisk
设置为“附加”。

diskattach.bicep:

@description('The virtual machine parameter object.')
param vm object = {
  vm_name: 'vmvktest'
  location: 'eastus'
  vmSize: 'Standard_D2s_v3'
  osType: 'Windows'
  sku: '2019-Datacenter'
}

@description('The Network security rules ID')
param nsg_id string = '/subscriptions/sub_ID/resourceGroups/vinay-rg/providers/Microsoft.Network/networkSecurityGroups/testvkvnsg'

@description('The Network interface card ID')
param nic_id string = '/subscriptions/sub_ID/resourceGroups/vinay-rg/providers/Microsoft.Network/networkInterfaces/testvknic'

@description('The managed disk ID')
param os_disk_id string = '/subscriptions/sub_ID/resourcegroups/vinay-rg/providers/Microsoft.Compute/disks/testvk-osdisk'

resource virtualMachine 'Microsoft.Compute/virtualMachines@2023-03-01' = {
  name: vm.vm_name
  location: vm.location
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    hardwareProfile: {
      vmSize: vm.vmSize
    }
    storageProfile: {
      osDisk: {
        osType: vm.osType
        name: 'testvk-osdisk'
        createOption: 'Attach'
        caching: 'ReadWrite'
        writeAcceleratorEnabled: false
        managedDisk: {
          id: os_disk_id
          storageAccountType: 'StandardSSD_LRS'
        }
        deleteOption: 'Detach'
      }
      dataDisks: []
    }
    networkProfile: {
      networkInterfaces: [
        {
          id: nic_id
          properties: {
            primary: true
          }
        }
      ]
    }
    diagnosticsProfile: {
      bootDiagnostics: {
        enabled: true
        storageUri: 'https://testttvkstoraccc.blob.core.windows.net/'
      }
    }
    licenseType: 'Windows_Server'
    priority: 'Regular'
    extensionsTimeBudget: 'PT1H30M'
  }
}

部署成功:

enter image description here

enter image description here

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.