【发布时间】:2021-11-08 07:18:55
【问题描述】:
我正在尝试通过 terraform 在 KVM 上部署 VM。
我希望我的虚拟机在主机网络中获得一个 IP,我的主机是 10.100.86.180。所以我使用的是 Bridge(当我手动部署 VM 时效果很好)
但是使用 terraform - 在“terraform apply”之后无法获得 IP,
我做错了什么?
这是我的 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:///14.7.1/output/KVMdisk1.qcow2"
format = "qcow2"
}
data "template_file" "user_data" {
template = "${file("${path.module}/cloud_init.cfg")}"
}
resource "libvirt_cloudinit_disk" "commoninit" {
name = "commoninit.iso"
user_data = "${data.template_file.user_data.rendered}"
}
resource "libvirt_network" "my_network" {
name = "default"
mode = "bridge"
addresses = ["10.100.86.0/24"]
bridge = "br0"
dhcp {
enabled = true
}
}
resource "libvirt_domain" "gw" {
name = "gw"
memory = "8192"
vcpu = 4
qemu_agent = true
network_interface {
# network_id = libvirt_network.my_network.id
addresses = ["10.100.86.5"]
bridge = "br0"
wait_for_lease = true
}
boot_device {
dev = [ "hd", "network"]
}
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
}
}
output "ips" {
value = libvirt_domain.gw.*.network_interface.0.addresses
}
它会抛出这个错误:
╵
╷
│ Error: Error: couldn't retrieve IP address of domain id: c49d77eb-62c4-4532-93c2-7d3f351b26e7. Please check following:
│ 1) is the domain running proplerly?
│ 2) has the network interface an IP address?
│ 3) Networking issues on your libvirt setup?
│ 4) is DHCP enabled on this Domain's network?
│ 5) if you use bridge network, the domain should have the pkg qemu-agent installed
│ IMPORTANT: This error is not a terraform libvirt-provider error, but an error caused by your KVM/libvirt infrastructure configuration/setup
│ timeout while waiting for state to become 'all-addresses-obtained' (last state: 'waiting-addresses', timeout: 5m0s)
│
│ with libvirt_domain.gw,
│ on main.tf line 41, in resource "libvirt_domain" "gw":
│ 41: resource "libvirt_domain" "gw" {
我正在使用 Bridge - 我发现 Qemu 来宾代理必须安装并在域内运行
为了发现连接到 LAN 的所有网络接口的 IP 地址。
如何在域上安装 Qemu 来宾代理?
我已经在我的主机上安装了,够了吗?
如何确保它正常工作?
【问题讨论】: