centos 如何在使用libvirt_volume.source的URL时指定HTTP身份验证(用户、密码)

cnwbcb6i  于 2022-11-07  发布在  其他
关注(0)|答案(1)|浏览(144)

我正在尝试使用Terraform配置虚拟机。我在此处给出了虚拟机的源映像:来源=“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" {*

谢谢你的帮助!

u2nhd7ah

u2nhd7ah1#

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

  • http://用户:密码@主机/路径 *

:)

相关问题