Terraform Libvirt - 如何在虚拟机管理程序中使用本地 qcow2 文件而不是云图像?

Terraform Libvirt - 如何在虚拟机管理程序中使用本地 qcow2 文件而不是云图像?

似乎 libvirt 提供商只接受预定义的云映像。我创建了自己的基础 qcow2 映像,该映像位于虚拟机管理程序本地,并希望将其用作 terraform libvirtd 的源文件。

这可行吗?

使用云镜像配置:

resource "libvirt_volume" "terraform-test" {
    name = "terraform-test.qcow2"
    pool = "default"
    source = "https://cloud.debian.org/images/cloud/buster/daily/20200324-210/debian-10-nocloud-amd64-daily-20200324-210.qcow2"
    format = "qcow2"

相反,我想像这样在虚拟机管理程序中使用本地文件:

resource "libvirt_volume" "terraform-test" {
    name = "terraform-test.qcow2"
    pool = "default"
    source = "/var/lib/libvirt/images/base-image.qcow2"
    format = "qcow2"



Error: Error while determining image type for /var/lib/libvirt/images/base-image.qcow2: Error while opening /var/lib/libvirt/images/base-image.qcow2: open /var/lib/libvirt/images/base-image.qcow2: no such file or directory

答案1

您必须像这样指定它:

resource "libvirt_volume" "terraform-test" {
  name = "terraform-test.qcow2"
  pool = "default"
  source = "file:///var/lib/libvirt/images/base-image.qcow2"
  format = "qcow2"

请记住,Terraform 将在控制器节点(Terraform 运行的位置)上查找图像。

答案2

也许问题在于您正在使用池和本地路径,请执行以下操作:

resource "libvirt_volume" "kube-node-1" {
  name = "kube-node-1"
  pool = "default"
  source = "base-image"
  format = "qcow2"
  full_clone = true
}

相关内容