Home > OS >  Azure bicep template tag OSDisk throws error on 'deleteOption' setting
Azure bicep template tag OSDisk throws error on 'deleteOption' setting

Time:01-03

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.

enter image description here

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: enter image description here

Portal: Using above Microsoft bicep code with version. I am able to successfully deploy the virtual machine with deleteOption: 'Delete'.

Console: enter image description here

I also checked in portal with json view:

enter image description here

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.

enter image description here

Result: enter image description here

  • Related