diff --git a/shared_modules/variables.tf b/shared_modules/variables.tf index 9a3bce7..117ebda 100644 --- a/shared_modules/variables.tf +++ b/shared_modules/variables.tf @@ -16,6 +16,18 @@ variable "pool_path" { default = "/opt/tf_tmp_storage" } +variable "disk_size_gb" { + description = "Disk size in GB" + type = number + default = 20 +} + +variable "disk_size_bytes" { + description = "Disk size in bytes" + type = number + default = 20 * 1024 * 1024 * 1024 +} + variable "instance_count" { description = "Number of instances to create" type = number diff --git a/shared_modules/volume.tf b/shared_modules/volume.tf index 582cdcf..e57fc55 100644 --- a/shared_modules/volume.tf +++ b/shared_modules/volume.tf @@ -1,9 +1,25 @@ -resource "libvirt_volume" "vm_disk" { - count = var.instance_count - name = "${var.vm_name}-${count.index}" +# Base volume (template/parent) +resource "libvirt_volume" "base_vm_image" { + name = "${var.vm_name}-base" pool = "${var.vm_name}-pool" source = var.image_location format = "qcow2" - depends_on = [libvirt_pool.tf_tmp_storage] -} \ No newline at end of file + depends_on = [ + libvirt_pool.tf_tmp_storage + ] +} + +# Clone volume with resizable size +resource "libvirt_volume" "vm_disk" { + count = var.instance_count + name = "${var.vm_name}-${count.index}" + pool = "${var.vm_name}-pool" + format = "qcow2" + size = var.disk_size_bytes + base_volume_id = libvirt_volume.base_vm_image.id + + depends_on = [ + libvirt_volume.base_vm_image + ] +}