AK
Size: a a a
AK
N
N
N
VR
N
N
S
DZ
EG
S
EG
EG
S
EG
S
S
S
S
EG
data "template_file" "vm" {
template = "${file("${path.module}/templates/vm")}"
vars = {
prefix = "${var.prefix}"
}
}
resource "libvirt_cloudinit_disk" "vm" {
provider = "libvirt.local"
name = "${var.prefix}-vm.iso"
pool = "${var.pool}"
user_data = "${data.template_file.vm.rendered}"
}
resource "null_resource" "vm" {
triggers {
data = "${data.template_file.vm.rendered}"
}
provisioner "local-exec" {
command = "[ -f debian-9.8.1-20190220-openstack-amd64.qcow2 ] || wget http://cdimage.debian.org/cdimage/openstack/current/debian-9.8.1-20190220-openstack-amd64.qcow2 ${path.root}/debian-9.8.1-20190220-openstack-amd64.qcow2"
}
provisioner "local-exec" {
command = "cp ${path.root}/debian-9.8.1-20190220-openstack-amd64.qcow2 /opt/${var.prefix}-vm.qcow2"
}
provisioner "local-exec" {
command = "qemu-img resize /opt/${var.prefix}-vm.qcow2 10G"
}
provisioner "local-exec" {
command = "chown libvirt-qemu:libvirt-qemu /opt/${var.prefix}-vm.qcow2"
}
}
resource "libvirt_volume" "debian-qcow2-vm" {
provider = "libvirt.local"
count = "${var.vm_count}"
name = "${var.prefix}-vm-${count.index}"
pool = "${var.pool}"
source = "/opt/vm.qcow2"
format = "qcow2"
depends_on = [
"null_resource.vm"
]
}
resource "libvirt_domain" "vm" {
provider = "libvirt.local"
count = "${var.vm_count}"
name = "${var.prefix}-vm-${count.index}"
memory = "${var.vm_ram}"
vcpu = "1"
cloudinit = "${libvirt_cloudinit_disk.vm.id}"
disk {
volume_id = "${libvirt_volume.debian-qcow2-vm.id}"
}
network_interface {
network_name = "default"
wait_for_lease = true
}
console {
type = "pty"
target_port = "0"
target_type = "serial"
}
console {
type = "pty"
target_type = "virtio"
target_port = "1"
}
graphics {
type = "vnc"
listen_type = "address"
autoport = true
}
}
output "vm_ip" { value = "${element(libvirt_domain.vm.*.network_interface.0.addresses[0], 0)}" }