Terraform: vSphere: creating a VM with an existing vmdk will not work

Created on 30 Aug 2016  ·  9Comments  ·  Source: hashicorp/terraform

Hello,

I'm working on the vSphere code of Terraform and have noticed a strange quirk.

@tkak, @dkalleg you worked on that so I'm pinging you guys but of course anyone may contribute.

at the end of the func addHardDisk (L1323 in master), we see

       …
        return vm.AddDevice(context.TODO(), disk)
    } else {
        log.Printf("[DEBUG] addHardDisk: Disk already present.\n")
        return nil
    }

When you specify a disk with a vmdk, the diskPath necessarily already points to an existing VMDK hence the disk will never be attached to the VM. There's no reason whatsoever to specify a vmdk path if the said disk does not already exist.

So I guess this is a bug.

I'll work on a patch since I need this feature. Can you confirm that it does not work as expected ?

bug providevsphere

Most helpful comment

+1 for this.

All 9 comments

Hey @ChloeTigre , I'm hoping you can clarify a bit since I'm not sure what you're pointing out. Two questions:
1) the diskPath necessarily already points to an existing VMDK hence the disk will never be attached to the VM. - Why wouldn't a vmdk be attached when the user specifies a path? I'm wondering if you mean to say 'if a vmdk is already associated with a vm, then that vmdk cannot be associated with _another_ vm', which is true. But that would be a user-error to provide an already mounted disk.
2) There's no reason whatsoever to specify a vmdk path if the said disk does not already exist. - You're right that this function does not work with a vmdk path which doesn't point to anything. The assumption is that the user (prior to the call to addHardDisk) either use the virtual_disk resource to create a vmdk or upload a vmdk file to a datastore.

Could you explain your use case a bit more? I'm not understanding the bug you're seeing.

Thanks

Hey @dkalleg

Basically, I upload a VMDK to vSphere (I worked on a patch to allow disk images cloning using vsphere_file resources, but that's out of the scope of this ticket)

If I add to a vsphere_virtual_machine a

disk {
  vmdk = "DATASTORE/path/to/cloned.vmdk"
  size = 8
}

the current code tries to _create_ the VMDK and this fails because it already exists. I just want it to _attach_ this VMDK in that case and fail if and only if it cannot either create or attach it (a VMDK cannot be attached, AFAIK, to 2 VMs).

I want to work on a patch for that or if you people have one upcoming I'll gladly test it.

Hello,

'been working on a patch. It's based on my refactored code base though so we may need to adjust… or go forward with this rebased code base.

See https://github.com/ChloeTigre/terraform/pull/8/files

Hi @ChloeTigre, thanks for explaining. I see the distinction now. There was an assumption that the user could not specify the size of an existing vmdk (which has a size). I'd say the bug here is that we didn't add a proper check such that the user can not provide both a size and vmdk attribute. Providing a size with a vmdk is analogous to a resize. Which isn't supported today.

So are you working on adding a resize for an existing vmdk?

Yes.

It is supported in my patch. I support disk resizes as a whole. However this has been done all on a refactored code base so we'll need to review it and merge it first. (a pr is open if you want to give a hand)

+1 for this.

Are there any ideas when this bug will be fixed/released? We use Packer to create the VDMK and then upload it via terraform "vsphere_file" resource and have noticed that it does not work.

+1

AWS provision EC2s with AMIs, Docker with docker images.

AMIs and docker images are pre-baked with OS. The equivalent in vsphere will be VMDKs.

This will be a blocker for using terraform to orchestrate in vsphere, just my 2 cents.

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings