-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Importing OSDisk of azurerm_windows_virtual_machine/azurerm_linux_virtual_machine #8794
Comments
We create our Azure VM's with azurerm_windows_virtual_machine and a generalized image from shared image gallery, which works great. We do use Azure recovery services vault for backup of these VMs. This is a disk level backup. If we need to restore the OS disk, this recovery creates a new disk that we then attach to the VM, putting the config out of sync. If we try to import the resulting VM config, we get the same error: Error: The "azurerm_windows_virtual_machine" resource doesn't support attaching OS Disks - please use the azurerm_virtual_machine resource instead There doesn't seem to be a way to use azurerm_windows_virtual_machine with Azure Recovery Services Vault and OS disk restores, which seems to be a major problem. |
Here is what such a recovered VM has properties set from a 'az vm show' command |
This would be very helpful when recreating a VM to move in/out of an availability set or similar. The VM would be recreated, but the OS and data would remain. |
This comment has been minimized.
This comment has been minimized.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Does the 3.0 provider unblock this item? With all of the changes with VMSS Flex and AVSets, this would be very helpful. |
Any update on this issue ? |
Up until recently, we had used the |
Hello community!
Ok, then you should ask:
==> This is due to this bug So now, I'm stuck in a vicious circle:
Is there any plan to fix new Thanks! |
Hey @jackofallops and @tombuildsstuff, Sorry to push on this - please share what is blocking this item. Hoping there's a way to help. Thank you! |
Just to bump this thread, I'm having the same problem too. A VM that was restored in Azure cannot be managed properly in Terraform. |
The "attach is not supported" gives situations where Terraform does not recover well. If the VM is getting into failed state, Terraform tries to recreate the VM. But there is a disk, and the disk cannot be attached, so Terraform tells about attachment not being possible. And it does not delete the disk itself, since the disk is not known by Terraform to exist. |
We at @swisspost miss the feature to attach os and data disks to "azurerm_windows_virtual_machine" & "azurerm_linux_virtual_machine". As mentioned by @gesnaud this is an very undesired situation, "azurerm_virtual_machine" supports this essential feature (especially when you want to use azure backup together with customer managed keys, the only option there for restore is create a new virtual machine see: https://learn.microsoft.com/en-us/azure/backup/restore-azure-encrypted-virtual-machines#before-you-start ). But is deprecated / superseded by the other resources "azurerm_windows_virtual_machine" & "azurerm_linux_virtual_machine" so we cannot use new features supported by the new resource blocks. So basically backup is useless because you never have the option to reimport into state. are there any news on this ? |
The import of existing VMs fails as soon as the osProfile property is not available - either by Azure Migrate or restore from backup. Its unclear to me why the provider does not support it - I commented out the check for this property: Is there any insights what will break? Thanks, |
We did not test CMK with the changes above. The project that I am working with is not using that. Also not sure if/where the osProfile is used in that case. The import of VMs to the state that were migrated with Azure Migrate or restored from Azure Backup could be imported. |
IMO the issue has nothing to do with cmk usage. The issue does not originate from cmk, using cmk just makes this issue apparent, because you only can do a new machine restore and therefore would have to re-import into tf state otherwise the vm would never be tracked by terraform. thx for sharing your tests, il ask HC once more directly referring to this thread. Hopefully they can confirm and a patch will fix this situation. |
I agree - might be a left-over. More testing would also help - please have a look: download: https://profile.mevitco.de/download/ecc03904-5700-4084-ac4e-17c6f4fc737f Remove the .txt extension after download and store it in a folder, e.g. /home/developer/go/bin Then create a file ~/.terraformrc and set the path to the folder containing the patched provider.
|
@tombuildsstuff @jackofallops - Would you be able to provide some details on what the issue is to see if the community can help? |
Is there any changes planned to support importing OsDisk to Is there any other option to migrate from |
Hey guys, don't know if someone else is still having problems with this, but we found a workaround which fulfils our requirements regarding this issue. |
I have the same issue. I already restored the VM from the backup. And the VM is currently in operation. In order to do the swap, I will need incur down time. Plus, my VM not only has OS disk, it has several data disks too. Then in that case, I will need to detach the data disks, keep them aside. Shut the VM down, detach the OS disk, keep that aside too. Then I will need to use my original terraform code to create a new VM. Swap the data disks. And then swap the OS disk on the new VM. With that I was able to bring the VM to the type of configuration that I am able to import into terraform using azurerm_windows_virtual_machine. I hope Hashcorp is listening on this. They need to come up with a better solution for this. |
Community Note
Description
Not being able to import the OSDisk has deadlocked me, since a machine that I am using uses a disk encryption set, I cannot fall back to azurerm_virtual_machine, since it does not support disk encryption sets.
New or Affected Resource(s)
Potential Terraform Configuration
References
The text was updated successfully, but these errors were encountered: