I am trying to create an Azure VM using bicep file:
resource linuxVm 'Microsoft.Compute/virtualMachines@2020-06-01' = {
name: linuxVm.vmName
location: location
properties: {
hardwareProfile: {
vmSize: linuxVm.vmSize
}
storageProfile: {
osDisk: {
createOption: 'FromImage'
deleteOption: 'Delete' //This line throws error
managedDisk: {
storageAccountType: linuxVm.osDiskType
}
}
When i want to delete the VM i want the OS disk also to be deleted so set this option: deleteOption: 'Delete' in storageprofile section.
But am getting this error during deployment of bicep:
"BadRequest","message": "Could not find member 'deleteOption' on object of type 'OSDisk'. Path 'properties.storageProfile.osDisk.deleteOption', line 1, position 231."target": "vm.properties.storageProfile.osDisk.deleteOption
What is the mistake here? Thanks
CodePudding user response:
I tried in my environment and got below results:
Initially, When I tried with version [2020-06-01]
linuxVm 'Microsoft.Compute/virtualMachines@2020-06-01'
in my environment. I got same error.
According to MS-DOCS, I tried with the resource virtual machine having document version [2021-11-01
]** i.e. vm 'Microsoft.Compute/virtualMachines@2021-11-01'
**
in bicep format.
Console:
Portal: Using above Microsoft bicep code with version. I am able to successfully deploy the virtual machine with deleteOption: 'Delete'.
Console:
I also checked in portal with json view
:
In my environment, I deleted the virtual machine manually to check the os disk
to delete and it successfully deleted both Virtual machine and os disk
perfectly.
Result: