dmacvicar / terraform-provider-libvirt

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

Size of base OS volume #821

Closed arunnalpet closed 3 years ago

arunnalpet commented 3 years ago

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?

jontey commented 3 years ago

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
}
MonolithProjects commented 3 years ago

One small correction. You are missing the .id

...
base_volume_id = libvirt_volume.base-centos7-qcow2.id
...
arunnalpet commented 3 years ago

Thanks, this approach works fine!