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

Error retrieving volume for disk: Storage volume not found: no storage vol with matching name 'centos7.qcow2' #949

Open gauravkhanande opened 2 years ago

gauravkhanande commented 2 years ago

System Information

[root@Terraform-vm libvirt]# lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 1 Core(s) per socket: 1 Socket(s): 4 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 85 Model name: Intel Xeon Processor (Skylake, IBRS) Stepping: 4 CPU MHz: 1795.781 BogoMIPS: 3591.56 Hypervisor vendor: KVM Virtualization type: full L1d cache: 32K L1i cache: 32K L2 cache: 4096K NUMA node0 CPU(s): 0-3

Linux distribution

Centos7

Terraform version

terraform -v
# Terraform v1.1.9

Provider and libvirt versions

terraform-provider-libvirt -version

provider registry.terraform.io/dmacvicar/libvirt v0.6.13

If that gives you "was not built correctly", get the Git commit hash from your local provider repository:

git describe --always --abbrev=40 --dirty

Checklist

Destination host: [root@h12 ~]# virsh -v 4.5.0

Description of Issue/Question

While creating a VM, weather you mention the volume or not in .tf file. we see the following error irrespective of configuration.
╷ │ Error: error retrieving volume for disk: Storage volume not found: no storage vol with matching name 'centos7.qcow2' │ │ with libvirt_domain.centos7, │ on vm-deploy.tf line 12, in resource "libvirt_domain" "centos7": │ 12: resource "libvirt_domain" "centos7" { │ ╵

Setup

(Please provide the full main.tf file for reproducing the issue (Be sure to remove sensitive information) main.tf terraform { required_providers { libvirt = { source = "dmacvicar/libvirt" version = "0.6.13" } } }

provider "libvirt" { uri = "qemu+ssh://virt@100.13.97.112/system?keyfile=/root/.ssh/id_rsa" }

test1.tf

Defining VM Volume

resource "libvirt_volume" "centos7-qcow2" {

name = "centos7.qcow2"

pool = "default" # List storage pools using virsh pool-list

source = "https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1805.qcow2"

source = "file:///var/lib/libvirt/images/CentOS-7-x86_64-minimal-2111.qcow2"

format = "qcow2"

}

Define KVM domain to create

resource "libvirt_domain" "centos7" { name = "centos7" memory = "2048" vcpu = 2

network_interface { network_name = "default" # List networks with virsh net-list }

disk {

volume_id = "${libvirt_volume.centos7-qcow2.id}"

}

console { type = "pty" target_type = "serial" target_port = "0" }

graphics { type = "spice" listen_type = "address" autoport = true } }

Steps to Reproduce Issue

(Include debug logs if possible and relevant).

2022-05-05T17:47:29.952+0530 [DEBUG] provider.terraform-provider-libvirt_v0.6.13: 2022/05/05 17:47:29 [TRACE] Checking for x86_64/hvm against i686/hvm 2022-05-05T17:47:29.952+0530 [DEBUG] provider.terraform-provider-libvirt_v0.6.13: 2022/05/05 17:47:29 [TRACE] Checking for x86_64/hvm against x86_64/hvm 2022-05-05T17:47:29.952+0530 [DEBUG] provider.terraform-provider-libvirt_v0.6.13: 2022/05/05 17:47:29 [DEBUG] Found 9 machines in guest for x86_64/hvm 2022-05-05T17:47:29.955+0530 [ERROR] vertex "libvirt_domain.centos7" error: error retrieving volume for disk: Storage volume not found: no storage vol with matching name 'centos7.qcow2' 2022-05-05T17:47:29.955+0530 [TRACE] vertex "libvirt_domain.centos7": visit complete, with errors 2022-05-05T17:47:29.955+0530 [TRACE] vertex "libvirt_domain.centos7": dynamic subgraph encountered errors: error retrieving volume for disk: Storage volume not found: no storage vol with matching name 'centos7.qcow2' 2022-05-05T17:47:29.955+0530 [ERROR] vertex "libvirt_domain.centos7" error: error retrieving volume for disk: Storage volume not found: no storage vol with matching name 'centos7.qcow2' 2022-05-05T17:47:29.955+0530 [TRACE] vertex "libvirt_domain.centos7": visit complete, with errors 2022-05-05T17:47:29.955+0530 [TRACE] vertex "libvirt_domain.centos7 (expand)": dynamic subgraph encountered errors: error retrieving volume for disk: Storage volume not found: no storage vol with matching name 'centos7.qcow2' 2022-05-05T17:47:29.955+0530 [ERROR] vertex "libvirt_domain.centos7 (expand)" error: error retrieving volume for disk: Storage volume not found: no storage vol with matching name 'centos7.qcow2' 2022-05-05T17:47:29.955+0530 [TRACE] vertex "libvirt_domain.centos7 (expand)": visit complete, with errors 2022-05-05T17:47:29.955+0530 [TRACE] dag/walk: upstream of "provider[\"registry.terraform.io/dmacvicar/libvirt\"] (close)" errored, so skipping 2022-05-05T17:47:29.956+0530 [TRACE] dag/walk: upstream of "root" errored, so skipping 2022-05-05T17:47:29.956+0530 [INFO] backend/local: refresh calling Refresh ╷ │ Error: error retrieving volume for disk: Storage volume not found: no storage vol with matching name 'centos7.qcow2' │ │ with libvirt_domain.centos7, │ on vm-deploy.tf line 12, in resource "libvirt_domain" "centos7": │ 12: resource "libvirt_domain" "centos7" { │ ╵ 2022-05-05T17:47:29.958+0530 [TRACE] statemgr.Filesystem: removing lock metadata file .terraform.tfstate.lock.info 2022-05-05T17:47:29.958+0530 [TRACE] statemgr.Filesystem: unlocking terraform.tfstate using fcntl flock 2022-05-05T17:47:29.959+0530 [DEBUG] provider.terraform-provider-libvirt_v0.6.13: 2022/05/05 17:47:29 [DEBUG] cleaning up connection for URI: qemu+ssh://virt@100.13.97.112/system?keyfile=/root/.ssh/id_rsa 2022-05-05T17:47:29.963+0530 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/dmacvicar/libvirt/0.6.13/linux_amd64/terraform-provider-libvirt_v0.6.13 pid=21511 2022-05-05T17:47:29.963+0530 [DEBUG] provider: plugin exited


Additional information:

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

gauravkhanande commented 2 years ago

This issue is solved by removing terraform.tfstate & terraform.tfstate.backup files from the tf directory. Seems like somehow tfstate & backup keeps track of old config which leads to showing error without any actual configuration in tf file.

ls

main.tf terraform.tfstate terraform.tfstate.backup

rm terraform.tfstate

rm: remove regular file ‘terraform.tfstate’? y

rm terraform.tfstate.backup

rm: remove regular file ‘terraform.tfstate.backup’? y

SamK commented 10 months ago

Try this:

terraform plan  -target=libvirt_volume.centos7-qcow2
terraform apply -target=libvirt_volume.centos7-qcow2