11

I am currently using virt-install to create new VMs on KVM/QEMU and then using Terraform to configure software on them. I want to combine these steps and use a Terraform provider to automate VM creation but then be able to tear the whole system down with a single command. Can anyone suggest a suitable Terraform provider to achieve this?

I am currently using matchbox with dnsmasq to PXE boot my VMs so all my solution needs to do is create a VM using Terraform with the necessary flags, for example:

virt-install --name "test" --network=bridge=bridge0,mac=FF:FF:FF:FF:FF:FF --boot=hd,network --memory=1024 --vcpus=2 --pxe --disk pool=default,size=10 --os-type=linux --os-variant=generic --noautoconsole --events on_poweroff=preserve

and be able to simply run terraform destroy to undo everything

9

The best KVM provider I've found so far is terraform-provider-libvirt. It provides full support for managing KVM VMs from Terraform and it still under very active development.

The only minor downside is that binaries are currently only available for openSUSE - other platforms require you to compile from source (like Terraform it's written in Go).

2
  • 1
    Now terraform-provider-libvirt release binary builds for Centos 7, Fedora 28, Ubuntu 18.04 and Open SUSE github.com/dmacvicar/terraform-provider-libvirt/releases
    – mmv-ru
    Mar 9 '19 at 0:45
  • I don't think that module provides pure automated --pxe boot. Yes, you can pass ignition files directly, putting under the question - do you need Matchbox at all, but... personally i also want to pass mac address and --pxe argument so VM could boot and grab ignition on its own without forcing Terraform to deal with those configs. In my case i have dedicated "bootstrap" server which is set up by Ansible and has DHCP, DNS, Matchbox, TFTP and iPXE. So basically, if i run the same command as author provided, my VMs runs and configures automatically.
    – Dzintars
    Oct 7 '19 at 10:20
1

There are now packages for CentOS, Fedora and Ubuntu as well:

https://software.opensuse.org/download/package?project=systemsmanagement:terraform&package=terraform-provider-libvirt

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.