Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Unable to linked clone from a template due to no existing snapshots despite templates technically being a snapshot #1156

Closed
arizvisa opened this issue Aug 6, 2020 · 2 comments
Labels
enhancement Type: Enhancement

Comments

@arizvisa
Copy link
Contributor

arizvisa commented Aug 6, 2020

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 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.

        if cmd.snapshot == "" {
                if cmd.link {
                        relocateSpec.DiskMoveType = string(types.VirtualMachineRelocateDiskMoveOptionsMoveAllDiskBackingsAndAllowSharing)
...
        } else {
                if cmd.link {
                        relocateSpec.DiskMoveType = string(types.VirtualMachineRelocateDiskMoveOptionsCreateNewChildDiskBacking)
...
                ref, ferr := cmd.VirtualMachine.FindSnapshot(ctx, cmd.snapshot)
...
                cloneSpec.Snapshot = ref
        }

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 the vsphere_virtual_machine.cloned-vm resource.

data "vsphere_virtual_machine" "template" {
...
}

resource "vsphere_virtual_machine" "cloned-vm" {
  clone {
    template_uuid = data.vsphere_virtual_machine.template.id
    linked_clone = true
  }
}

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

  • 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
@arizvisa arizvisa added the enhancement Type: Enhancement label Aug 6, 2020
arizvisa added a commit to arizvisa/hashicorp-terraform-provider-vsphere that referenced this issue Aug 6, 2020
arizvisa added a commit to arizvisa/hashicorp-terraform-provider-vsphere that referenced this issue Aug 6, 2020
@arizvisa
Copy link
Contributor Author

arizvisa commented Aug 6, 2020

PR #1158 fixes this.

arizvisa added a commit to arizvisa/hashicorp-terraform-provider-vsphere that referenced this issue Aug 7, 2020
@ghost
Copy link

ghost commented Oct 10, 2020

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 ghost locked as resolved and limited conversation to collaborators Oct 10, 2020
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
enhancement Type: Enhancement
Projects
None yet
Development

No branches or pull requests

2 participants