dmacvicar / terraform-provider-libvirt

Terraform provider to provision infrastructure with Linux's KVM using libvirt
Apache License 2.0
1.54k stars 457 forks source link

[Feature Request] Non destructive volume resize #952

Open Hybrid512 opened 2 years ago

Hybrid512 commented 2 years ago

System Information

Linux distribution

Ubuntu 20.04/22.04

Terraform version

Terraform v1.0.11 on linux_amd64

Provider and libvirt versions

terraform-provider-libvirt 0.6.14

Checklist

Description of Issue/Question

Terraform can detect state differences between an existing volume size and an expected new volume size but with the current libvirt provider, volumes are first deleted then re-created with the new size. This is ok for reproductible and immutable environments but this is annying especially when you have big volumes or data you would like to avoid losing or restoring (repository mirroring, datasets, ...). Libvirt enable resizing a volume without destrying/re-creating it, I can do it easily with virsh just like this :

virsh vol-resize <MyVolume> <NewSizeInBytes> --pool <MyVolumePool>

Only conditions for that :

Steps to Reproduce Issue

Any VM with at least a volume

jtackaberry commented 1 year ago

It's actually possible to do an online resize with libvirt:

virsh blockresize somevm --path /vms/somevm-root.qcow2 --size 10G

And this is detected immediately within the guest:

[  267.339414] virtio_blk virtio2: [vda] new size: 20971520 512-byte logical blocks (10.7 GB/10.0 GiB)
[  267.339423] vda: detected capacity change from 12582912 to 20971520

I'd love to see this possible via terraform-provider-libvirt too.

JSmith-Aura commented 1 year ago

I'd love to see this as well, would make life a lot more fun (also thanks for all the work you do on this project)

merlinfvr commented 3 months ago

@dmacvicar would you accept a PR for this issue? Being able to resize volumes non-destructively would be great.

Libvirt already supports this via virStorageVolResize and virDomainBlockResize. It seems the former works on any volume not currently attached to a running domain while the latter supports resizing on a running domain (but presumably does not work on volumes not currently attached to a domain as it requires a reference to one).

Is there any way to easily check if a volume is currently attached to a (and if yes, which) domain? Looping all domains to check if they have a specific volume attached will be very inefficient.