Skip to content
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

Add support to resize r/vsphere_virtual_disk #851

Closed
jsmilani opened this issue Sep 27, 2019 · 35 comments · Fixed by #2244
Closed

Add support to resize r/vsphere_virtual_disk #851

jsmilani opened this issue Sep 27, 2019 · 35 comments · Fixed by #2244
Assignees
Labels
acknowledged Status: Issue or Pull Request Acknowledged area/storage Area: Storage enhancement Type: Enhancement size/m Relative Sizing: Medium upstream/govmomi Upstream: vmware/govmomi
Milestone

Comments

@jsmilani
Copy link

Right now the vsphere_virtual_disk resource does not permit any changes, but we need to increase disk size on occasion. It is unreasonable to expect us to find a manual workaround to copy data from an old disk to a new larger disk. I would understand requiring a new disk when decreasing the size since that is generally not possible on most systems. During our tests we found the 'eagerZeroedThick' type does not allow resizing by vSphere but 'lazy' should permit increases in size.

NOTE: All fields in the vsphere_virtual_disk resource are currently immutable and force a new resource if changed.

Terraform Version

0.12.x

vSphere Provider Version

1.12.0

Affected Resource(s)

Please list the resources as a list, for example:

  • vsphere_virtual_disk

Expected Behavior

We expect to be able to increase the size of a type='lazy' vsphere_virtual_disk.

Actual Behavior

Disk wants to be recreated and we will lose all data.

@aareet aareet added the enhancement Type: Enhancement label Oct 1, 2019
@aareet
Copy link
Contributor

aareet commented Oct 1, 2019

@jsmilani this appears to be a duplicate of #150

@jsmilani
Copy link
Author

jsmilani commented Oct 1, 2019

#150 mentions resizing 10 comments deep, but it is phrased as a question. I don't think it qualifies as a duplicate since the original message itself doesn't address resizing nor does its proposed solution. I believe resizing doesn't necessarily require stopping the VM, but I have not figured out how to do that in the vcenter UI yet.

@jsmilani
Copy link
Author

jsmilani commented Oct 1, 2019

I just wanted to clarify that it doesn't need to be 'lazy' to resize, both 'lazy' and 'eagerZeroedThick' are confirmed resizable but I have not tested 'thin'. Resizing works while it is mounted to a running vsphere_virtual_machine, but the volume still needs to be manually expanded (this is normal and expected). It doesn't seem to work at all when it is mounted to a vsphere_virtual_machine with the disk_sharing='sharingMultiWriter' option.

@hashibot
Copy link

This issue has been open 180 days with no activity. If this issue is reproducible with the latest version of the provider and with Terraform 0.12, please comment. Otherwise this issue will be closed in 30 days.

@hashibot hashibot added the stale Status: Stale label Apr 21, 2020
@jsmilani
Copy link
Author

Adding comment to keep this alive. It is very much an issue still.

@ghost ghost removed the stale Status: Stale label Apr 21, 2020
@aareet aareet added the needs-triage Status: Issue Needs Triage label Apr 21, 2020
@Vox1984
Copy link

Vox1984 commented May 20, 2020

Issue is happening in 0.12.23

@Karthikeyanraman94
Copy link

Hello Colleagues, we are still facing this issue
as mentioned in below comment can this be done to help us to resize the disk provisioned by vsphere_virtual_disk resource.
#150 (comment)

We need to use the disk for logsearch and cassandra for which resizing will be regularly required..

@Karthikeyanraman94
Copy link

Karthikeyanraman94 commented Jul 10, 2020

@bill-rich: Could you please help in taking forward this enhancement request

@arizvisa
Copy link
Contributor

arizvisa commented Aug 7, 2020

I notice there's no resourceVSphereVirtualDiskUpdate function in the vsphere/resource_vsphere_virtual_disk.go file. To accomplish this, would it just require someone to implement the ability to diff the configuration in the file via a couple of conditionals?

@dcardellino
Copy link

Also interested in having the ability to resize vsphere_virtual_disks.
We have virtual machines with "external" created disks as data disks and sometimes we need to resize them and have to do some dirty hacks with manipulating the terraform state.

@bill-rich bill-rich added acknowledged Status: Issue or Pull Request Acknowledged size/m Relative Sizing: Medium labels Aug 18, 2020
@arizvisa
Copy link
Contributor

@dcardellino, please +1 the first comment in this issue so your request reaches hashicorp's analytics (or whatever they're doing).

@mouradk78
Copy link

@dcardellino very much a issue we need addressing as well. Any timeline for this ? Thanks

@angelbarrera92
Copy link

+1 here

@dcardellino
Copy link

Any Update here?

@armand-s2h
Copy link

Any update ?

@garvitpatel196
Copy link

Any Update

@rihenperry
Copy link

Struggling to find a way to resize disk partition with terraform for VM created from packer template.

@arizvisa
Copy link
Contributor

@rihenperry, you can script the govc client using the vm.disk.change parameter until you or someone else submits a PR to get the implementation of this feature jumpstarted.

@magnusstrandberg1
Copy link

any updates on resizing disks, we really want need this feature.

@keelerad
Copy link

Has anyone got any suggestions, we clone from a template VM with a 30GB didk to a 50GB disk, the VM shows as having a 50 GB disk but cant see the free space anywhere in the rhel VM to extend logical volumes ?

@ichundu
Copy link

ichundu commented Jan 5, 2022

+1

1 similar comment
@magnusstrandberg1
Copy link

+1

@arizvisa
Copy link
Contributor

Ugh. As a reminder, please do not put "+1" as an additional comment. nobody will _ever_ see that shit unless they're already part of the issue in question... you need to +1 the original post.

@tenthirtyam
Copy link
Collaborator

Please be mindful of language and the code of conduct.

@erSitzt
Copy link

erSitzt commented Jan 25, 2022

Isnt this always a problem to be solved by a provisioner with access to the os running/using the disks ?

In linux you would rescan the scsi bus and resize the disks via something like

echo 1 > /sys/class/scsi_disk/2\:0\:0\:0/device/rescan # adjust device number
growpart /dev/sda 2 
# then for lvm
pvresize /dev/sda2 
lvextend -l+100%FREE /dev/srv-git-vg/root
resize2fs /dev/mapper/srv--git--vg-root

# or for normal partitions
resize2fs /dev/sda2

I think you can even do this via cloud-init on boot ?

In Windows this can be done by powershell as well if i remember correctly...

TLDR
I think there are two issues mixed up here...

  • Resizing exitings vm disks
  • Resising filesystems in a vm
  • Resizing different types of vm disks

The first is working with terraform at least with thin prov disks for me.
I second is outside the scope of the vsphere-provider as it require different commands/tools depending on the used disk layouts and filesystems

If this issue is only about the third variant, the subject of the issue should be adjusted to reflect that

@jsmilani
Copy link
Author

The OS maps the device to a physical volume and then to a logical volume so it is true that it must get involved to make the actual volume increase in size, but the prerequisite is the device has been resized first and that is done by VSphere by modifying the virtual disk. We are not asking to solve the OS side of the problem, but we want to be able to increase the virtual disk size via terraform. Right now the workaround is to manually increase the disk size in the VCenter UI then update the terraform resource to match the manual change. We want to just be able to update the terraform resource to increase disk (not decrease). Decreasing size is outside of scope since it would destroy the volume if the OS had already claimed the new space.

@erSitzt
Copy link

erSitzt commented Jan 25, 2022

@jsmilani Yeah, i misread something here...
my bad, sorry...

can i downvote my own comment ? :)

@tenthirtyam
Copy link
Collaborator

Votes are only counted on the original
description issue

@tenthirtyam tenthirtyam changed the title Feature request: ability to resize vsphere_virtual_disk Add support to resize vsphere_virtual_diskresource Feb 3, 2022
@tenthirtyam tenthirtyam changed the title Add support to resize vsphere_virtual_diskresource Add support to resize vsphere_virtual_disk resource Feb 3, 2022
@tenthirtyam tenthirtyam changed the title Add support to resize vsphere_virtual_disk resource Add support to resize r/vsphere_virtual_disk Feb 19, 2022
@tenthirtyam tenthirtyam added the area/storage Area: Storage label Feb 22, 2022
@tenthirtyam tenthirtyam added this to the Research milestone Feb 25, 2022
@RobertCGouge
Copy link

Somewhat related, when doing a terraform destroy after updating a template that has a different sized vmdk, terraform fails with error. Is it possible to have the delete action ignore this specific error?

Error: disk.0: virtual disk "disk0": virtual disks cannot be shrunk (old: 150 new: 78) with vsphere_virtual_machine.vm[0], on main.tf line 78, in resource "vsphere_virtual_machine" "vm":

@scryptio
Copy link

It’s been 3 years now. 28 votes so far. How many does it need to get this going? I know this is voluntarily work and I wish I could PR this (don’t get it to work) …
But we still have to use a workarounds while it works perfectly with defined disks in r/vsphere_virtual_machine already. Which is also not about the OS side!

@arizvisa
Copy link
Contributor

arizvisa commented Nov 29, 2022

I'm unable to contribute to this software anymore as it was originally for a one-off thing and I don't use it anymore, but as per my question 2y ago (#851 (comment)), it "seems" like one would just need to add an "Update" field to

func resourceVSphereVirtualDisk() *schema.Resource {
return &schema.Resource{
Create: resourceVSphereVirtualDiskCreate,
Read: resourceVSphereVirtualDiskRead,
Delete: resourceVSphereVirtualDiskDelete,
Importer: &schema.ResourceImporter{
State: resourceVSphereVirtualDiskImport,
},
Schema: map[string]*schema.Schema{
// Size in GB

Which appears pretty similar to the following snippet...

func resourceVSphereVirtualMachineUpdate(d *schema.ResourceData, meta interface{}) error {

However you'd probably want to add some abstractions for resizing to https://github.com/hashicorp/terraform-provider-vsphere/blob/main/vsphere/internal/helper/virtualdisk/virtual_disk_helper.go that's similar to this disk sizing code from govc (https://github.com/vmware/govmomi/blob/b505edbbb3b58ced3c2ea6cf8fb2fb2860302721/govc/vm/disk/change.go#L155). That'd likely get some of govc's vm.disk.change functionality started (so that others can add more attributes that they care about).

Anyways, feel free to correct me if my assumptions are incorrect.

@dimitarproynov
Copy link
Collaborator

Hi all,

The ExtendVirtualDisk method of VirtualDiskManager is missing from the govmomi:

https://github.com/vmware/govmomi/blob/939e78dc19bf32a5fef077079e9263e058ea5ee3/object/virtual_disk_manager.go

However, the method is present in the vim API.

We'll need to:

  • include the method in VirtualDiskManager in govmomi
  • wait for new govmomi release
  • bump govmomi version in the provider
  • add the support to extend virtual disk in the provider (somewhat trivial)

Regards,
_Proynov

@arizvisa
Copy link
Contributor

arizvisa commented Aug 9, 2024

Awesome.

Copy link

This functionality has been released in v2.8.3 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
acknowledged Status: Issue or Pull Request Acknowledged area/storage Area: Storage enhancement Type: Enhancement size/m Relative Sizing: Medium upstream/govmomi Upstream: vmware/govmomi
Projects
None yet
Development

Successfully merging a pull request may close this issue.