/tf-vm

Terraform Modules for libvirt provider

Primary LanguageHCLMIT LicenseMIT

Terraform Modules for libvirt provider

This repository contains terraform modules to quickly create libvirt VMs from cloud images using Terraform with libvirt provider.

test Terraform-Version libvirt-Version license

Requirements

  • KVM supported Linux Machine
  • libvirtd is up and running
  • Terraform.

Usage

  • modules/net - Creates a Network

    module "vnet" {
      source = "git::https://github.com/tprasadtp/tfm-libvirt.git//modules/net"
      name   = "test"
      domain = "test.kvm"
      subnet = "192.168.127.0/24"
    }
  • modules/vm - Creates VM

    module "vm" {
      source            = "git::https://github.com/tprasadtp/tfm-libvirt.git//modules/vm"
      cloudimage        = pathexpand("~/Virtual/installers/focal-server-cloudimg-amd64.img")
      cloudimage_format = "raw"
      name              = "test"
      network           = "test"
      vcpu              = 1
      memory            = 256
      vcpu_model_host   = true
      user_data         = file("${path.module}/user-data.cfg")
    }

Notes

  • This module is meant to quickly create headless machines in a reproducible way.
  • VMs with UI are NOT supported!, vm module even strips off all video/spice devices!
  • Advanced configs are not supported. You might look into provider's documentation for creating VMs which support additional features.

Tests

  • Tests spin up VMs and asserts they are running with right config using ansible.
  • You can use already installed version of ansible if you wish. Otherwise, poetry install

Cloud images

VMs use cloud images as its easier to configure them them using cloud-init.

Supported Guest OS