87dc196f77b9aef0c751ae6d3f61748eef4b3986
Modern libvirt-driven Terraform examples
This repository contains Terraform recipes to deploy various modern virtual machines using QEMU and libvirt.
By modern, it is meant virtual machines that leverage the use of modern desktop-oriented technologies, like UEFI firmware and recent virtual motherboard chipset (i.e. Phyllome OS itself), by staying as close as possible as domain definitions maintained here.
Organization
The folder multiple contains two subfolders, one with shared modules and the other with the various target deployment environments.
The idea is to reuse modules across multiple virtual machines and operating systems.
.:
environments shared_modules
./environments:
cloud_init.yaml ubuntu-cloud-server-2404-bios
./environments/ubuntu-cloud-server-2404-bios:
ubuntu-cloud-server-2404-bios.tf
./shared_modules:
cloud-init.tf domain.tf network.tf outputs.tf pool.tf provider.tf variables.tf volume.tf
Requirements
- QEMU
- libvirt
- Terraform provider for Libvirt
- An SSH key pair to connect to machines that are deployed using cloud-init. See instructions below.
Assumptions
- Your Linux x86_64-based machine has at least 4 GB of available memory and 2 CPUs
Limitations
- Only a deployment is supported at a time, as some resources are shared. E.g. Ubuntu cannot be deployed alongside Debian.
How to use it
- Clone this repository
- Run the following to generate a public key pair
$ ssh-keygen -t rsa -b 4096 -f ~/.ssh/terraform_key -C "terraform-deployment"
- Make the script executable
$ chmod +x update_ssh_keys.sh
- Run the script (it will use terraform_key by default), and will update all
main.tffile so that they use the previously generated key:
$ ./update_ssh_keys.sh
Alternatively, you can use your own public key and update it manually in the
main.tfdeployment file
- Navigate to one of the available deployment
$ cd environments/ubuntu-cloud-server-2404-bios/
- Initialize your terraform environment
$ terraform init
- Plan the deployment
$ terraform plan
- Deploy
$ terraform deploy
- Identify the name of the machine, which requires elevated privileges
# virsh list --all
Id Name State
--------------------------------------------
2 u24-bios-0 running
- Fetch IP address
# virsh domifaddr u24-bios-0
- Connect to the machine with the user
groot
$ ssh groot@10.17.3.107
groot@ubuntu:~$
- Logout
$ exit
- Destroy the machine
$ terraform destroy
Resources
Description
This repository contains terraform examples to deploy various modern virtual machines using QEMU and libvirt
Languages
Shell
61.2%
HCL
37.2%
XSLT
1.6%