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

Disks in domain xml definition end up with driver type='raw' instead of type='qcow2' #811

Open bpetit opened 3 years ago

bpetit commented 3 years ago

System Information

Linux distribution

Ubuntu 20.04.1 LTS

Terraform version

terraform -v
Terraform v0.13.5

Provider and libvirt versions

terraform-provider-libvirt -version
./terraform-provider-libvirt 0.6.3+git.1604843676.67f4f2aa
Compiled against library: libvirt 6.0.0
Using library: libvirt 6.0.0
Running hypervisor: QEMU 4.2.1
Running against daemon: 6.0.0

Checklist

Description of Issue/Question

Setup

(Please provide the full main.tf file for reproducing the issue (Be sure to remove sensitive information)

resource "libvirt_volume" "scaphtest01" {
    name = "scaphtest01.qcow2"
    source = "/home/bpetit/git/scaphandre/tests/qemu/1/template-debian-10.qcow2"
    pool = libvirt_pool.ansible_iaas_pool.name
    format = "qcow2"
    depends_on = [libvirt_pool.ansible_iaas_pool]
}
resource "libvirt_network" "iaaslocal" {
    name = "iaaslocal"
    mode = "nat"
    domain = "example.local"
        addresses = [
        "192.168.99.1/24"
        ]
    }
output "instance_ip_addr" {
    value = libvirt_domain.scaphtest01.network_interface.0.addresses
}
resource "libvirt_pool" "ansible_iaas_pool" {
  name = "ansible_iaas_pool"
  type = "dir"
  path = "/var/lib/libvirt/images/ansible_iaas"
}
terraform {
 required_version = ">= 0.13"
  required_providers {
    libvirt = {
      source  = "dmacvicar/libvirt"
      version = "0.6.3"
    }
  }
}
provider "libvirt" {
  uri = "qemu:///system"
}
resource "libvirt_domain" "scaphtest01" {
    name = "scaphtest01"
    memory = 512
    vcpu = 1
            disk {
        file = libvirt_volume.scaphtest01.id
    }
                    network_interface {
        network_id = libvirt_network.iaaslocal.id
        hostname = "scaphtest01"
        addresses = [
                        "192.168.99.3"
                        ]
    }
            console {
        type = "pty"
        target_port = "0"
        target_type = "serial"
    }
}

Steps to Reproduce Issue

Apply the configuration above. In the end, my primary qcow2 drive appears as unbootable. In the xml of the domain I see that it is configured with: <driver name='qemu' type='raw'/>. I expected to get <driver name='qemu' type='qcow2'/> as the file ends with .qcow2. I even enforced the type in the volume definition as you can see with format = "qcow2".


Additional information:

Do you have SELinux or Apparmor/Firewall enabled? Yes Some special configuration? No Have you tried to reproduce the issue without them enabled? No

I create this issue for reference and eventual discussion. I have tested a fix that seems to work and will propose it as a PR in a few minutes.