I have installed Ubuntu 20.04 with KVM and I tried to create Centos 7 guest VM via Terraform.
It is saying "Could not open '/mnt/storage/centos7tes.qcow2': Permission denied", but I tried with root and with user. Also I use Cockpit as GUI.
provider.tf
terraform {
required_providers {
libvirt = {
source = "dmacvicar/libvirt"
}
}
}
provider "libvirt" {
## Configuration options
#uri = "qemu:///system"
#alias = "server2"
uri = "qemu+ssh://[email protected]/system"
}
main.tf
# Defining VM Volume
resource "libvirt_volume" "centos7-qcow2" {
name = "centos7tes.qcow2"
pool = "default"
#source = "https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2"
source = "./CentOS-7-x86_64-GenericCloud.qcow2"
format = "qcow2"
}
# get user data info
data "template_file" "user_data" {
template = "${file("${path.module}/cloud_init.cfg")}"
}
# Use CloudInit to add the instance
resource "libvirt_cloudinit_disk" "commoninit" {
name = "commoninit.iso"
pool = "default" # List storage pools using virsh pool-list
user_data = "${data.template_file.user_data.rendered}"
}
# Define KVM domain to create
resource "libvirt_domain" "centos7" {
name = "centos7"
memory = "2048"
vcpu = 2
network_interface {
network_name = "default"
}
disk {
volume_id = "${libvirt_volume.centos7-qcow2.id}"
}
cloudinit = "${libvirt_cloudinit_disk.commoninit.id}"
console {
type = "pty"
target_type = "serial"
target_port = "0"
}
graphics {
type = "spice"
listen_type = "address"
autoport = true
}
}
# Output Server IP
output "ip" {
value = "${libvirt_domain.centos7.network_interface.0.addresses.0}"
}
libvirt_volume.centos7-qcow2: Still creating... [40s elapsed]
libvirt_volume.centos7-qcow2: Still creating... [50s elapsed]
libvirt_volume.centos7-qcow2: Still creating... [1m0s elapsed]
libvirt_volume.centos7-qcow2: Still creating... [1m10s elapsed]
libvirt_volume.centos7-qcow2: Creation complete after 1m14s [id=/mnt/storage/centos7tes.qcow2]
libvirt_domain.centos7: Creating...
╷
│ Error: Error creating libvirt domain: internal error: process exited while connecting to monitor: 2021-12-11T23:02:04.400339Z qemu-system-x86_64: -blockdev {"driver":"file","filename":"/mnt/storage/centos7tes.qcow2","node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}: Could not open '/mnt/storage/centos7tes.qcow2': Permission denied
│
│ with libvirt_domain.centos7,
│ on libvirt.tf line 23, in resource "libvirt_domain" "centos7":
│ 23: resource "libvirt_domain" "centos7" {