$ cat main.tf terraform { required_providers { libvirt = { source = "dmacvicar/libvirt" } } } provider "libvirt" { uri = "qemu:///system" } resource "libvirt_volume" "os_image_ubuntu" { name = "os_image_ubuntu" pool = "default" source = "./bionic-server-cloudimg-amd64.img" format = "qcow2" } resource "libvirt_volume" "disk_ubuntu_resized" { name = "disk" base_volume_id = libvirt_volume.os_image_ubuntu.id pool = "default" size = 34359738368 # 1073741824*32 ou 1024*1024*1024*32 } data "template_file" "user_data" { template = file("${path.module}/cloud_init.cfg") } # Use CloudInit to add our ssh-key to the instance resource "libvirt_cloudinit_disk" "cloudinit_ubuntu_resized" { name = "cloudinit_ubuntu_resized.iso" user_data = data.template_file.user_data.rendered pool = "default" } resource "libvirt_domain" "ubuntu-terraform" { name = "ubuntu-terraform" memory = "2048" vcpu = 2 cpu { mode = "host-passthrough" } cloudinit = libvirt_cloudinit_disk.cloudinit_ubuntu_resized.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" } disk { volume_id = libvirt_volume.disk_ubuntu_resized.id } graphics { type = "spice" listen_type = "address" autoport = true } } output "ip" { value = libvirt_domain.ubuntu-terraform.network_interface[0].addresses[0] }