将 URL 用于 libvirt_volume.source 时如何指定 HTTP 身份验证(用户、密码)

How to specify HTTP authentication (user, password) when using an URL for libvirt_volume.source

我正在尝试使用 Terraform 置备 VM。 我给了虚拟机的源图像 这里: source = "http://10.1.1.160/Builds/14.7.1.10_0.39637/output/KVM/14.7.1.10_0.39637-disk1.qcow2"

但是这个站点需要用户名和密码。 我可以在哪里以及如何在我的 tf 文件中指定此站点的凭据?

这是我的 main.tf 文件:

terraform {
  required_providers {
    libvirt = {
      source = "dmacvicar/libvirt"
    }
  }
}

provider "libvirt" {
    uri = "qemu:///system"
}

resource "libvirt_volume" "centos7-qcow2" {
  name = "centos7.qcow2"
  pool = "default"
  source = "http://10.1.1.160/Builds/14.7.1.10_0.39637/output/KVM/14.7.1.10_0.39637-disk1.qcow2"
  format = "qcow2"
}

# Define KVM domain to create
resource "libvirt_domain" "gw" {
  name   = "gw"
  memory = "8192"
  vcpu   = 4

  network_interface {
    network_name = "default"
  }

  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
  }
}

当我 运行 terraform apply 我得到这个错误:

*Error while determining image type for http://10.1.1.160/Builds/14.7.1.10_0.39637/output/KVM/14.7.1.10_0.39637-disk1.qcow2: Can't retrieve partial header of resource to determine file type: http://10.1.1.160/Builds/14.7.1.10_0.39637/output/KVM/14.7.1.10_0.39637-disk1.qcow2 - 401 Authorization Required

   with libvirt_volume.centos7-qcow2,
   on main.tf line 13, in resource "libvirt_volume" "centos7-qcow2":
   13: resource "libvirt_volume" "centos7-qcow2" {*

感谢帮助!

我刚刚将密码和用户添加到 URL,如下所示:

http://用户:密码@host/path

:)