title: Cannot attach an existing OS disk if the VM is created from a platform, user or a shared gallery image
body: <p>Creating a azure virtual machine and attaching managed disks (Created from snapshots)</p>
  <p>Getting the error,</p>
  <p>&quot;Cannot attach an existing OS disk if the VM is created from a platform, user or a shared gallery image</p>
  <p>Tried tweaks in &quot;create option&quot; as &quot;Copy&quot;, &quot;Import&quot; etc, but none worked out</p>
  <p>Code as follows,</p>
  <pre><code>        provider &quot;azurerm&quot; {
      subscription_id = &quot;abcd&quot;
      features {}
  }
  
  resource &quot;azurerm_managed_disk&quot; &quot;example&quot; {
    name                 = &quot;managed-disk-01&quot;
    location             = &quot;East US&quot;
    resource_group_name  = &quot;RG-APP&quot;
    storage_account_type = &quot;Premium_LRS&quot;
    create_option        = &quot;Copy&quot;
    disk_size_gb         = &quot;127&quot;
    source_resource_id   = azurerm_snapshot.example.id
    os_type              = &quot;Windows&quot;
  }
  
  resource &quot;azurerm_snapshot&quot; &quot;example&quot; {
    name                = &quot;snapshot&quot;
    location            = &quot;East US&quot;
    resource_group_name = &quot;RG-APP&quot;
    create_option       = &quot;Copy&quot;
    source_uri          = &quot;/subscriptions/abcv/resourceGroups/RG-APP/providers/Microsoft.Compute/disk/AppA_OsDisk_1_0e&quot;
  }
  
  data &quot;azurerm_subnet&quot; &quot;subnet&quot; {
     name = &quot;vnet-sn-app&quot;
     resource_group_name = &quot;rg-network&quot;
     virtual_network_name = &quot;vnet&quot;
  }
  
  resource &quot;azurerm_network_interface&quot; &quot;example&quot; {
    name                = &quot;example-nic&quot;
    location            = &quot;East US&quot;
    resource_group_name = &quot;RG-APP&quot;
  
    ip_configuration {
      name                          = &quot;ipconfig&quot;
      subnet_id                     = &quot;${data.azurerm_subnet.subnet.id}&quot;
      private_ip_address_allocation = &quot;Dynamic&quot;
    }
  }
  
  resource &quot;azurerm_availability_set&quot; &quot;DemoAset&quot; {
    name                = &quot;example-aset&quot;
    location            = &quot;East US&quot;
    resource_group_name = &quot;RG-APP&quot;
  }
  resource &quot;azurerm_virtual_machine&quot; &quot;example&quot; {
    name                = &quot;example-machine-01&quot;
    resource_group_name = &quot;RG-APP&quot;
    location            = &quot;East US&quot;
    vm_size                = &quot;Standard_F2&quot;
    availability_set_id = azurerm_availability_set.DemoAset.id
    delete_os_disk_on_termination = false
    delete_data_disks_on_termination = false
    network_interface_ids = [
      azurerm_network_interface.example.id,
    ]
    os_profile {
      computer_name  = &quot;hostname&quot;
      admin_username = &quot;testadmin&quot;
      admin_password = &quot;Password1234!&quot;
    }
    os_profile_windows_config {
      provision_vm_agent =&quot;true&quot;
      }
  
    storage_os_disk {
      name              = &quot;myosdisk1&quot; 
      managed_disk_id   = &quot;${azurerm_managed_disk.example.id}&quot;
      caching           = &quot;ReadWrite&quot;
      create_option     = &quot;Attach&quot;
    }
  
    storage_image_reference {
      publisher = &quot;MicrosoftWindowsServer&quot;
      offer     = &quot;WindowsServer&quot;
      sku       = &quot;2016-Datacenter&quot;
      version   = &quot;latest&quot;
    }
  }
  </code></pre>
  <p>Please help in guiding to solve this issue. Thank you!</p>