Introduction to Terraform Provider for Libvirt
Overview
The Terraform Provider for Libvirt is designed to facilitate the provisioning of servers on a Libvirt host through the Terraform tool. This project allows teams to enjoy the benefits of software-defined infrastructure where Terraform collaborates with traditional and cost-effective Linux and KVM virtualization infrastructure. The aim is to support dynamic DevOps, development, and testing processes by integrating KVM resources with other infrastructures managed by Terraform.
However, it's important to note that not every advanced feature of Libvirt is supported by default. The project maintains focus on simplifying the mapping from Terraform and making it manageable.
Getting Started
The provider can be automatically installed from the Terraform Registry. Users need to specify the desired provider version in their main.tf
file:
terraform {
required_providers {
libvirt = {
source = "dmacvicar/libvirt"
}
}
}
provider "libvirt" {
// Configuration options
}
To commence, run the initialization command:
$ terraform init
Creating Your First Virtual Machine
Here's a simple setup example for creating a virtual server resource:
provider "libvirt" {
uri = "qemu:///system"
}
Alternatively, the URI can be set using the LIBVIRT_DEFAULT_URI
environment variable. Define a Libvirt domain as follows:
resource "libvirt_domain" "terraform_test" {
name = "terraform_test"
}
Users can then execute the terraform
commands to plan, apply, and destroy the infrastructure:
$ terraform init
$ terraform plan
$ terraform apply
$ terraform destroy
More advanced examples and detailed documentation can be accessed on the Terraform Registry.
Manual Installation
For users preferring the manual installation process, the provider can be downloaded from the GitHub releases section. Detailed installation guidance can be found in the Terraform documentation.
Building from Source
Required tools include Go, which can be installed from its official site. The following steps are necessary to build the provider from source:
git clone https://github.com/dmacvicar/terraform-provider-libvirt.git
cd terraform-provider-libvirt
make
The built binary will be named terraform-provider-libvirt
.
Usage of Multiple Hypervisors
Users can target different Libvirt hosts by creating multiple instances of the provider configuration, allowing simultaneous usage across various environments.
Utilizing QEMU Agent
Users can employ QEMU Agent within domains to assist in managing various OS-level tasks. To enable network interface details retrieval via QEMU Agent, users must explicitly set qemu_agent = true
in their configuration.
Projects Using Terraform-Provider-Libvirt
A variety of upstream projects utilize this provider, including:
- Sumaform: Rapid deployment and testing of Uyuni and SUSE Manager setups.
- HA-Cluster-SAP: Automated high availability and SAP deployments.
- Ceph-Open-Terrarium: Configuration and testing of CEPH clusters.
- Kubic Projects: Terraform scripts using KVM/libvirt.
- Openshift 4 Installer: Relies on this provider for Libvirt platform orchestration.
Contributions and Maintenance
Contributions to the project are governed by a set of accepted categories such as code maintenance, testing enhancements, modernizing the codebase, and creating simplified resource versions.
Authors and License
The project is authored by Duncan Mac-Vicar P. and licensed under Apache 2.0. The development structure draws inspiration from Softlayer and Google Terraform provider sources. More detailed author and contributor information is available on the project repository.