Terraform Libvirt-如何使用本地 qcow2 文件

Terraform Libvirt-如何使用本地 qcow2 文件

我尝试为基于 kvm 和 debian 的 kubernetes 集群配置一些节点。我想使用 Debian 11 Genericcloud 映像和 clound-init 来初始化它。所以我将 debian baseimge/var/lib/libvirt/images/templates放在偏僻的机器,kvm 在其中运行。我查阅了一些教程和 serverfault 帖子,他们说我应该在我的代码中像这样处理它:

resource "libvirt_volume" "diskimages" {
  count = var.instance_count
  name = "${var.instance_name}-${count.index}.qcow2"
  pool = libvirt_pool.diskimage_pool.name
  source = var.baseimage
  format = "qcow2"
}

但是当我执行这个时,baseimage = "/var/lib/libvirt/images/templates/debian-11-genericcloud-amd64.qcow2"我得到以下错误:

Error: error while determining image type for /var/lib/libvirt/images/templates/debian-11-genericcloud-amd64.qcow2: error while opening /var/lib/libvirt/images/templates/debian-11-genericcloud-amd64.qcow2: open /var/lib/libvirt/images/templates/debian-11-genericcloud-amd64.qcow2: no such file or directory
│   with libvirt_volume.diskimages[4],
│   on libvirt.tf line 25, in resource "libvirt_volume" "diskimages":
│   25: resource "libvirt_volume" "diskimages" {

当我尝试解决方案时也一样serverfault 帖子。然后我的代码如下所示:

# create .qcow2 image for vm
resource "libvirt_volume" "diskimages" {
  count = var.instance_count
  name = "${var.instance_name}-${count.index}.qcow2"
  pool = libvirt_pool.diskimage_pool.name
  source = "file///var/lib/libvirt/images/templates/debian-11-genericcloud-amd64.qcow2"
  format = "qcow2"
}

我遇到了同样的错误。

有人知道这里出了什么问题吗?提前谢谢

答案1

好像你错过了““,应该是

file://<path>

因此

file:///var/lib/libvirt/images/templates/debian-11-genericcloud-amd64.qcow2

你的情况

相关内容