You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Making a linked-clone from a template is apparently not possible due to the assertion of it needing a snapshot. This assertion is re-iterated throughout the internet as when cloning from a non-template requires a snapshot. This makes sense for virtual machines because their disks would be in use which would interfere with other users of said disk. Templates, however, are essentially already snapshots and so therefore linked clones should be possible. Actually, technically, there's no real difference between templates and virtual machines other than a flag which tells VMware that it shouldn't tamper with the machine's disk. This technology is actually the same from VMWare's Workstation in which you're not allowed to modify the disks from a template hence being able to perform a full or linked clone from them.
According to the vsphere/internal/vmworkflow/virtual_machine_clone_subresource.go, Terraform's vSphere provider is using the types.VirtualMachineRelocateDiskMoveOptionsCreateNewChildDiskBacking to clone all virtual machines. However, if the types.VirtualMachineRelocateDiskMoveOptionsMoveAllDiskBackingsAndAllowSharing is used then the backing disk of the source template will be moved to the correct datastore and then shared with all virtual machines that use it. This would then allow performing linked-clones with a template or even without a snapsho.
It might be good to expose all of the available disk relocation types from the docs somehow, but I'd personally prefer the simpler interface that you guys have already implemented.
Cross-checking against the implementation of vm.clone from govc seems to include the following logic when a snapshot is not found. Again, as there's other types that are available in the API, I'm not sure if this is the correct logic to do for any virtual machine other than a template where you can guarantee that the disk is locked as read-only. But it seems to work nonetheless.
In this example configuration, the data.vsphere_virtual_machine.template data source is marked as a template (without snapshots). This would allow performing a linked clone of it which would result in the disk being moved onto the same datastore, and then that disk being shared with the vsphere_virtual_machine.cloned-vm resource.
I think this problem is universal as all of the blogs and related articles suggest that you need to convert back to a virtual machine, take a snapshot, then mark back as a template. As such I imagine there's a lot of references to this problem. I will search after I merge my patches into a submittable PR.
Community Note
Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
If you are interested in working on this issue or have submitted a pull request, please leave a comment
The text was updated successfully, but these errors were encountered:
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!
ghost
locked as resolved and limited conversation to collaborators
Oct 10, 2020
# for freeto subscribe to this conversation on GitHub.
Already have an account?
#.
This issue is a placeholder for a pull request.
Description
Making a linked-clone from a template is apparently not possible due to the assertion of it needing a snapshot. This assertion is re-iterated throughout the internet as when cloning from a non-template requires a snapshot. This makes sense for virtual machines because their disks would be in use which would interfere with other users of said disk. Templates, however, are essentially already snapshots and so therefore linked clones should be possible. Actually, technically, there's no real difference between templates and virtual machines other than a flag which tells VMware that it shouldn't tamper with the machine's disk. This technology is actually the same from VMWare's Workstation in which you're not allowed to modify the disks from a template hence being able to perform a full or linked clone from them.
The documentation at https://webcache.googleusercontent.com/search?q=cache:oVq53OL38-kJ:https://pubs.vmware.com/vsphere-50/topic/com.vmware.wssdk.pg.doc_50/PG_Ch11_VM_Manage.13.4.html+&cd=1&hl=en&ct=clnk&gl=us confirms this logic, and the available types are documented at https://vdc-download.vmware.com/vmwb-repository/dcr-public/b525fb12-61bb-4ede-b9e3-c4a1f8171510/99ba073a-60e9-4933-8690-149860ce8754/doc/vim.vm.RelocateSpec.DiskMoveOptions.html).
According to the
vsphere/internal/vmworkflow/virtual_machine_clone_subresource.go
, Terraform's vSphere provider is using thetypes.VirtualMachineRelocateDiskMoveOptionsCreateNewChildDiskBacking
to clone all virtual machines. However, if thetypes.VirtualMachineRelocateDiskMoveOptionsMoveAllDiskBackingsAndAllowSharing
is used then the backing disk of the source template will be moved to the correct datastore and then shared with all virtual machines that use it. This would then allow performing linked-clones with a template or even without a snapsho.It might be good to expose all of the available disk relocation types from the docs somehow, but I'd personally prefer the simpler interface that you guys have already implemented.
Cross-checking against the implementation of
vm.clone
fromgovc
seems to include the following logic when a snapshot is not found. Again, as there's other types that are available in the API, I'm not sure if this is the correct logic to do for any virtual machine other than a template where you can guarantee that the disk is locked as read-only. But it seems to work nonetheless.Potential Terraform Configuration
In this example configuration, the
data.vsphere_virtual_machine.template
data source is marked as a template (without snapshots). This would allow performing a linked clone of it which would result in the disk being moved onto the same datastore, and then that disk being shared with thevsphere_virtual_machine.cloned-vm
resource.References
I think this problem is universal as all of the blogs and related articles suggest that you need to convert back to a virtual machine, take a snapshot, then mark back as a template. As such I imagine there's a lot of references to this problem. I will search after I merge my patches into a submittable PR.
Community Note
The text was updated successfully, but these errors were encountered: