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

Possibility to extend volume #923

Closed wojtasool closed 2 years ago

wojtasool commented 2 years ago

Terraform version

1.0.0

Provider and libvirt versions

0.6.12

Is it possibility to extend volume based on source image? For example this is my code for volumes

resource "libvirt_volume" "node_root_disk" {
  for_each = { for domain in local.domains : domain.name => domain }
  name     = "${each.key}.qcow2"
  pool     = "FAST"
  source   = var.default_os_disk
}

It creates for each VM a disk, but these are not possible to be extended at creation time.

Would it be possible to add such possibility?

achivu-ai commented 2 years ago

Hi,

I commented here because I ran into similar issue trying to extend the volume with the given examples I saw here. The base image is created but the volume is smaller than expected.

jenkins@test:~/terraform/kvm$ terraform --version
Terraform v1.1.2
on linux_amd64
+ provider registry.terraform.io/dmacvicar/libvirt v0.6.12

My main.tf file looks like this:

terraform {
  required_version = ">= 0.13"
   required_providers {
     libvirt = {
       source  = "dmacvicar/libvirt"
       version = "0.6.12"
     }
   }
 }

 # instance the provider
 provider "libvirt" {
   #uri = "qemu:///system"
 }

 resource "libvirt_pool" "blade2pool" {
   name = "blade2pool"
   type = "dir"
   path = "/home/kvm/blade2_storage"
 }

 resource "libvirt_volume" "base-image" {
   name = "base-image"
   pool = libvirt_pool.blade2pool.name
   source = "my_image.qcow2"
   format = "qcow2"
 }

 resource "libvirt_volume" "volume-img" {
   name = "volume-img"
   pool = libvirt_pool.blade2pool.name
   base_volume_id = libvirt_volume.base-image.id
   size = 21474836480
 }

resource "libvirt_domain" "blade2" {
  name   = "test-blade"
  memory = 8192
  vcpu = 4

  disk {
    volume_id = "${libvirt_volume.volume-img.id}"
  }

  network_interface {
      bridge = "br0"
  }
}

After terraform apply, I can see the base image created in the mentioned pool with the original size, but the volume created based on it is smaller than the source image, it doesn't have the expected 20G I mentioned for size. The result is as below:

-rw-r--r-- 1 libvirt-qemu kvm 1855389696 Jan 12 14:46 base-image
-rw-r--r-- 1 libvirt-qemu kvm     196928 Jan 12 15:02 volume-img

Can you please help me with this? I am really stuck here. Maybe is something wrong with the code I use.

Many thanks in advance!

dmacvicar commented 2 years ago

The definition and whole point of COW (Copy-on-Write) means that only changed blocks will be written to volume-img. If you haven't changed anything, the derived volume is just a bit of metadata and data will be coming from the data image. The derived volume will grow as needed.