I am trying to create a VM from an existing Os disk image that has been created by another module. I am getting the error below
Cannot attach an existing OS disk if the VM is created from a platform, user or a shared gallery image. (Code: InvalidParameter, Target: osDisk)
The code is from a decompiled arm template, I can see its missing the local login password. At this stage I am trying to get it to work to build a VM. I did some research ad found a user with a similar issue here , however the code/solution is incomplete and thus I could not follow it.
@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'
}
}