I am trying to deploy VM via terraform on KVM.
I want my VM to get an IP in the Host network, my host is 10.100.86.180. so I am using Bridge (which works well when I deploy VM manually)
but with terraform- it can't get an IP after "terraform apply",
what am I doing wrong?
here is my 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
}
it throws this error:
╵
╷
│ 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" {
I am working with Bridge - I found that the Qemu guest agent must be installed and running inside of the domain
in order to discover the IP addresses of all the network interfaces attached to a LAN.
how can I install the Qemu guest agent on the domain?
I have already install it on my Host, is it enough?
How can I ensure it is working properly?