This repo provides a testbed where an on-prem KVM-based virtual environment is present and Terraform being utilised for automated provisioning. A typical three-tier infrastructure consisting of arbitrary number of VMs will be up and running within seconds. A medium story with more detailed discussion is here. --> https://medium.com/@emrah-t/provisioning-automation-with-terraform-on-libvirt-and-kvm-ba6fa177ffea
- A Linux computer (VM or physical) with the required KVM/libvirt components installed (kvmhost). --> https://linuxhint.com/install-kvm-ubuntu-22-04/
- Terraform binaries installed (v1.3.7) --> https://developer.hashicorp.com/terraform/cli/install/apt
- An intermediate level of domain (Terraform, KVM/libvirt) knowledge.
- Remote state backend configured for more flexibility and collaboration.
- libvirt provider is utilised as the main component. --> https://registry.terraform.io/providers/dmacvicar/libvirt/latest/docs
- There are three types of VMs in main.tf; load balancers, application servers and database servers where all of their numbers and specs (CPU, memory, network config etc.) are dynamic and parameterized.
- Each type of server has three libvirt resources; domain, volume and cloudinit_disk.
- Variables come from variables.tf.
- network_config.cfg and cloud_init.cfg are the files for cloudinit where former is for network config and latter for config such as user creation and access.
- Resulting topology is somewhat as it is given below.
- "Terraform validate & init & plan & apply & destroy" lifecycle applies.
- Beware that some changes in the config (such as CPU count) requires destroy&recreate after "terraform apply" whereas some can be handled in-place. Luckily, Terraform is smart enough to deal with it.
- Within seconds, arbitrary number (bound with your resources of course) of VMs are provisioned, modified to your desired state or destroyed.
Screencast.webm
What you need with the infrastructure! Another IaC tool, Ansible would be nice to install and configure an application.