i am working with KVM to deploy VM. i configure Bridge and the Network Source at the VM shows:
then i tried to deploy the same VM using terraform
but in the VM Network Source it shows:
it also change it to the vm i deploy manually (without terraform).
how can I retrieve it to the regular way?
i am afraid this change my network bridge configuration.
which cause the VM guest to not get IP by DHCP (as i configure in the tf file)
this is my tf file:
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.10_0.39637-disk1.qcow2"
format = "qcow2"
}
data "template_file" "user_data" {
template = file("${path.module}/cloud_init.cfg")
}
data "template_file" "cloudinit_network" {
template = file("${path.module}/network.cfg")
}
resource "libvirt_cloudinit_disk" "cloud_init" {
name = "commoninit.iso"
user_data = data.template_file.user_data.rendered
network_config = data.template_file.cloudinit_network.rendered
}
resource "libvirt_network" "test_network" {
name = "test_network"
mode = "bridge"
bridge = "br0"
# addresses = ["10.100.86.5"]
dhcp {
enabled = true
}
}
# Define KVM domain to create
resource "libvirt_domain" "gw" {
name = "gw"
memory = "8192"
vcpu = 4
cloudinit = libvirt_cloudinit_disk.cloud_init.id
qemu_agent = true
network_interface {
# network_name = "default"
network_id = libvirt_network.test_network.id
}
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
}
and this is my network.cfg:
version: 2
ethernets:
eth0:
dhcp4: true
gateway4: 10.100.86.254
thanks for any help

