Terraform-provider-libvirt: Size of base OS volume

Created on 15 Dec 2020  路  3Comments  路  Source: dmacvicar/terraform-provider-libvirt

Hi,
How can we specify size for OS volume? Currently its documented that, OS volume will assume the size of disk image.

I am installing some software on top of this OS volume, which has a per-requisite that OS volume should be 40gb at least.

Example:

# 40GB OS volume
variable "diskBytes" { default = 1024*1024*1024*40 }

resource "libvirt_volume" "centos7-qcow2" {
  name = "centos7.qcow2"
  pool = "images"
  source = "./CentOS-7-x86_64-GenericCloud.qcow2"
  format = "qcow2"
  size = var.diskBytes
}

In the above sample, specifying 'size' attribute will fail, because we have specified 'source' already. So the size of this volume will be just around 800MB, while I want it to be atleast 40Gb. How can I achieve this?

community question

All 3 comments

You will need to use the base_volume_id (https://github.com/dmacvicar/terraform-provider-libvirt/blob/master/website/docs/r/volume.html.markdown#argument-reference)

resource "libvirt_volume" "base-centos7-qcow2" {
  name = "CentOS-7-x86_64-GenericCloud.qcow2"
  pool = "images"
  source = "./CentOS-7-x86_64-GenericCloud.qcow2"
  format = "qcow2"
}

resource "libvirt_volume" "centos7-qcow2" {
  name = "centos7.qcow2"
  pool = "images"
  format = "qcow2"
  size = var.diskBytes
  base_volume_id = libvirt_volume.base-centos7-qcow2
}

One small correction. You are missing the .id

...
base_volume_id = libvirt_volume.base-centos7-qcow2.id
...

Thanks, this approach works fine!

Was this page helpful?
0 / 5 - 0 ratings