Terraform oVirt Provider: Declarative Automation for oVirt and RHEV Infrastructure

The Terraform oVirt provider bridges Terraform declarative configuration with the oVirt Engine API, enabling automated provisioning and management of virtualization infrastructure for oVirt and Red Hat Virtualization environments. The plugin exposes Terraform resources and data sources that map directly to oVirt entities such as virtual machines, templates, networks, storage domains, and hosts. By using the provider, operators can define entire oVirt topologies as code, integrate them into OpenShift installation and management workflows, and reproduce environments consistently across development, staging, and production.

The provider exists in two related forms. The upstream community provider maintained under the oVirt organization provides a generic Terraform interface for oVirt resources. A wrapper variant in the OpenShift Terraform Providers repository is built around the upstream provider, specifically version 2.2.0-alpha2, with security enhancements and modifications to integrate with the OpenShift ecosystem. Both variants rely on the Terraform Plugin SDK for implementing resources, data sources, and provider functionality and communicate with oVirt via the go-ovirt client libraries.

Architecture and OpenShift Integration

The oVirt provider follows the standard Terraform provider architecture. It implements resources, data sources, and provider functionality using the Terraform Plugin SDK. The provider serves as an interface between Terraform and the oVirt API and enables the provisioning of oVirt virtual machines, templates, networks, and other resources through Terraform as part of OpenShift installation and management workflows.

The OpenShift Terraform Providers repository version is a wrapper around the upstream oVirt Terraform provider. It is a critical component for deploying OpenShift on oVirt infrastructure and provides a Terraform interface to manage oVirt resources, allowing for automated, declarative provisioning of infrastructure as part of the OpenShift installation process.

The provider is built on top of the upstream oVirt Terraform provider, with additional security patches and integration with the OpenShift ecosystem. It leverages the Terraform Plugin SDK and the go-ovirt client libraries to communicate with the oVirt Engine API.

Logging is implemented using the Terraform Plugin Log library and allows for different verbosity levels. The logging system is implemented using the Terraform Plugin Log library and allows for different verbosity levels.

Error handling is comprehensive. The provider implements comprehensive error handling to provide meaningful error messages for various failure scenarios. Error information is propagated back to Terraform to assist in troubleshooting and resolving issues.

Provider Origins and Upstream Relationship

The provider can be used with Terraform 0.13+ from the Terraform registry with the following required provider configuration.

hcl terraform { required_providers { ovirt = { source = "ovirt/ovirt" } } } provider "ovirt" { # Configuration options }

The original roots of this provider were developed by Maigard at EMSL-MSC and was extensively worked on by imjoey. In 2021 a complete rewrite was made on the basis of go-ovirt-client to support better testability. The original provider can still be found in the v0 branch.

The detailed documentation can be found in the Terraform registry. If you wish to contribute to this Terraform provider please head over to the contributing guide for a detailed tutorial on how to write code here.

Installation and Build Workflow

The Terraform oVirt provider is used to interact with the many resources supported by oVirt. In this guide, we will cover how you can install Terraform oVirt provider plugin and use it to automate oVirt / RHEV Virtualization environment operations. The provider needs to be configured with the proper credentials before it can be used.

Step 1: Install Go

We will build the plugin from source code. For this, we need Go (Golang) installed on the local workstation. Refer to guides below and official Go documentation for how to steps.

  • Install Go on Fedora
  • Install Go on Ubuntu / CentOS 7
  • Install Go CentOS 8 / RHEL 8

Step 2: Install Terraform

oVirt terraform provider requires Terraform installed on the machine from where the build is being done.

  • Install Terraform on Linux
  • Install Terraform on Windows 10 / Windows Server 2019

Check version

bash $ terraform version Terraform v0.12.12

Step 2: Build oVirt Terraform plugin

Let’s now build oVirt plugin for Terraform. But first, clone the project source from Git.

bash mkdir -p $HOME/terraform-providers/ cd $HOME/terraform-providers/ git clone https://github.com/oVirt/terraform-provider-ovirt.git

To compile the provider, run:

bash cd terraform-provider-ovirt make build

This will build the provider and put the provider binary in the $GOPATH/bin directory.

After building, Terraform initialization proceeds normally.

bash $ terraform init Initializing provider plugins... Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work.

If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary.

The initialization is successful and you can start to use the plugin to automate oVirt/RHEL Virtualization management.

Provider Configuration and Authentication

Provider configuration requires connection details for the oVirt Engine API. If omitted, environment variables are used.

  • Ovirt_URL
  • username – Required. The username for accessing oVirt engine API. If omitted, the Ovirt_USERNAME environment variable is used.
  • password – Required. The password of the user for accessing oVirt engine API. If omitted, the Ovirt_PASSWORD environment variable is used.

Configuration parameters can be summarized as follows:

Parameter Required Description
ovirt_url No Engine API URL. Falls back to Ovirt_URL environment variable
username Yes Username for Engine API. Falls back to Ovirt_USERNAME environment variable
password Yes Password for Engine API. Falls back to Ovirt_PASSWORD environment variable

Supported Resources and Data Sources

It is not just the creation of VMs that you can use terraform for, but provisioning of other resources such as Disk, Network, Snapshots etc. In our previous article, we discussed how you can use Terraform to automate your KVM infrastructure.

Among the resources supported by terraform oVirt provider are:

  • ovirt_cluster
  • ovirt_datacenter
  • ovirt_disk
  • ovirtdiskattachment
  • ovirt_host
  • ovirtmacpool
  • ovirt_network
  • ovirt_snapshot
  • ovirtstoragedomain
  • ovirt_tag
  • ovirt_user
  • ovirt_vm
  • ovirt_vnic
  • ovirtvnicprofile

The data sources are:

  • ovirt_authzs
  • ovirt_clusters
  • ovirt_datacenters
  • ovirt_disks
  • ovirt_hosts
  • ovirtmacpools
  • ovirt_networks
  • ovirt_nics
  • ovirt_storagedomains
  • ovirt_users
  • ovirt_vms
  • ovirtvnicprofiles

A module is a container for multiple resources that are used together.

Resource Category Examples
Compute ovirtvm, ovirtsnapshot, ovirt_tag
Storage ovirtdisk, ovirtdiskattachment, ovirtstorage_domain
Network ovirtnetwork, ovirtvnic, ovirtvnicprofile, ovirtmacpool
Host/Cluster ovirthost, ovirtcluster, ovirt_datacenter
Identity ovirt_user
Data Source Category Examples
Inventory ovirtvms, ovirthosts, ovirt_clusters
Networking ovirtnetworks, ovirtnics, ovirtvnicprofiles
Storage ovirtdisks, ovirtstoragedomains
Identity ovirtusers, ovirtauthzs

The official documentation for Terraform oVirt provider provides more details on the usage of these resources and data sources. We’ll only cover the most basic and common use cases.

VM Template Preparation and Provisioning Workflow

VM Template preparation
Ensure your VM template have cloud-init installed.

CentOS / Rocky Linux

bash sudo yum -y update sudo yum -y install epel-release sudo yum install cloud-init cloud-utils-growpart sudo systemctl enable --now cloud-init

Debian / Ubuntu

bash sudo apt-get -y update sudo apt-get -y install cloud-init

Once the template is prepared, Terraform configurations can reference the template for ovirt_vm resources and attach disks, networks, and VNIC profiles declaratively.

Release History and Dependency Evolution

The provider repository shows active maintenance of dependencies and compatibility.

Release v2.2.0 includes the following changes:

Change Author
Bump github.com/hashicorp/terraform-plugin-sdk/v2 from 2.19.0 to 2.20.0 dependabot[bot]
Update to go 1 18 engelmi
Bump terraform plugin sdk engelmi
Bump github.com/ovirt/go-ovirt-client/v2 from 2.0.0-alpha04 to 2.0.0 dependabot[bot]
bump go-ovirt-client version engelmi
Bump github.com/hashicorp/terraform-plugin-sdk/v2 from 2.22.0 to 2.23.0 dependabot[bot]
Updating ancient gotestfmt dupondje
Bump github.com/hashicorp/terraform-plugin-sdk/v2 from 2.23.0 to 2.24.0 dependabot[bot]
update default assignee engelmi
Update wait for ip doc engelmi
Bump github.com/ovirt/go-ovirt-client/v2 from 2.0.1 to 2.1.0 dependabot[bot]
OCPBUGS-6586: Updating go-ovirt-client engelmi
Bump github.com/hashicorp/terraform-plugin-sdk/v2 from 2.24.1 to 2.25.0 dependabot[bot]
update go-ovirt-client to 3.0.0-alpha1 engelmi
Bump github.com/hashicorp/terraform-plugin-docs from 0.13.0 to 0.14.0 dependabot[bot]
Bump github.com/hashicorp/terraform-plugin-docs from 0.14.0 to 0.14.1 dependabot[bot]
ci: update action versions dupondje
Add storagedomainid to templatediskattachment_override dupondje
ci: update .goreleaser.yml dupondje

These updates illustrate ongoing work to keep the Terraform Plugin SDK, go-ovirt-client, and CI tooling current.

Logging and Error Handling

The logging system is implemented using the Terraform Plugin Log library and allows for different verbosity levels.

The provider implements comprehensive error handling to provide meaningful error messages for various failure scenarios. Error information is propagated back to Terraform to assist in troubleshooting and resolving issues.

Conclusion

The Terraform oVirt provider delivers declarative, repeatable control over oVirt and RHEV infrastructure through Terraform. The upstream community provider offers a broad set of resources and data sources for VMs, disks, networks, hosts, storage domains, and identity objects, with a modern rewrite based on go-ovirt-client to improve testability. The OpenShift Terraform Providers wrapper builds on version 2.2.0-alpha2 with security enhancements and tight integration for OpenShift deployments on oVirt.

Installation from source requires Go and Terraform, followed by cloning the GitHub repository and building with make build. Provider authentication relies on oVirt Engine URL, username, and password, with environment variable fallbacks. VM templates should include cloud-init for automated provisioning, and the resource set covers the full lifecycle of virtualization infrastructure.

Dependency maintenance is active, with regular bumps to the Terraform Plugin SDK, go-ovirt-client, and documentation tooling. Logging via the Terraform Plugin Log library and comprehensive error propagation provide operational visibility. Together, these characteristics make the provider suitable for infrastructure as code pipelines, OpenShift automation, and large-scale oVirt management.

Sources

  1. deepwiki.com/openshift/terraform-providers/4.4-ovirt-provider
  2. github.com/oVirt/terraform-provider-ovirt
  3. computingpost.medium.com/how-to-install-terraform-ovirt-rhev-plugin-322224e12dbb
  4. github.com/oVirt/terraform-provider-ovirt/releases
  5. neveropen.tech/how-to-provision-vms-on-ovirt-rhev-with-terraform

Related Posts