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 our 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. Use the guide below to install Terraform:

Install Terraform on Linux

Install Terraform on Windows 10 / Windows Server 2019

Check version

$ 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.

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

To compile the provider, run:

cd terraform-provider-ovirt
make build

This will build the provider and put the provider binary in the $GOPATH/bin directory. Output looks like below.

==> Checking that code complies with gofmt requirements...
go install
go: downloading github.com/hashicorp/terraform v0.12.2
go: downloading github.com/ovirt/go-ovirt v4.3.4+incompatible
go: extracting github.com/ovirt/go-ovirt v4.3.4+incompatible
go: extracting github.com/hashicorp/terraform v0.12.2
go: downloading github.com/hashicorp/go-hclog v0.0.0-20181001195459-61d530d6c27f
go: downloading github.com/zclconf/go-cty v0.0.0-20190516203816-4fecf87372ec
go: downloading github.com/hashicorp/logutils v1.0.0
go: downloading github.com/hashicorp/go-plugin v1.0.1-0.20190610192547-a1bc61569a26
go: downloading github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
go: downloading github.com/hashicorp/hcl2 v0.0.0-20190515223218-4b22149b7cef
go: downloading github.com/hashicorp/terraform-config-inspect v0.0.0-20190327195015-8022a2663a70
go: downloading github.com/hashicorp/go-version v1.1.0
go: extracting github.com/hashicorp/logutils v1.0.0
go: downloading github.com/mitchellh/mapstructure v1.1.2
go: extracting github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
go: extracting github.com/hashicorp/go-hclog v0.0.0-20181001195459-61d530d6c27f
go: downloading github.com/hashicorp/hil v0.0.0-20190212112733-ab17b08d6590
go: extracting github.com/hashicorp/go-version v1.1.0
go: downloading github.com/hashicorp/go-getter v1.3.0
go: extracting github.com/hashicorp/terraform-config-inspect v0.0.0-20190327195015-8022a2663a70
go: extracting github.com/hashicorp/go-plugin v1.0.1-0.20190610192547-a1bc61569a26
go: downloading github.com/agext/levenshtein v1.2.2
go: extracting github.com/zclconf/go-cty v0.0.0-20190516203816-4fecf87372ec
go: extracting github.com/mitchellh/mapstructure v1.1.2
go: downloading github.com/mitchellh/cli v1.0.0
go: extracting github.com/agext/levenshtein v1.2.2
go: downloading github.com/hashicorp/go-uuid v1.0.1
go: downloading github.com/davecgh/go-spew v1.1.1
go: extracting github.com/hashicorp/hil v0.0.0-20190212112733-ab17b08d6590
go: extracting github.com/hashicorp/go-uuid v1.0.1
go: downloading github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f
go: extracting github.com/mitchellh/cli v1.0.0
go: downloading github.com/hashicorp/go-multierror v1.0.0
go: downloading github.com/posener/complete v1.2.1
go: extracting github.com/hashicorp/go-getter v1.3.0
go: extracting github.com/davecgh/go-spew v1.1.1
go: downloading github.com/hashicorp/go-cleanhttp v0.5.0
go: extracting github.com/hashicorp/go-multierror v1.0.0
go: extracting github.com/posener/complete v1.2.1
go: downloading github.com/vmihailenco/msgpack v4.0.1+incompatible
go: downloading github.com/fatih/color v1.7.0
go: downloading github.com/mattn/go-isatty v0.0.5
go: extracting github.com/hashicorp/go-cleanhttp v0.5.0
go: downloading github.com/hashicorp/go-safetemp v1.0.0
go: extracting github.com/mattn/go-isatty v0.0.5
go: downloading github.com/aws/aws-sdk-go v1.19.18
go: extracting github.com/hashicorp/go-safetemp v1.0.0
go: extracting github.com/vmihailenco/msgpack v4.0.1+incompatible
go: extracting github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f
go: downloading google.golang.org/grpc v1.18.0
go: extracting github.com/hashicorp/hcl2 v0.0.0-20190515223218-4b22149b7cef
go: downloading github.com/bgentry/speakeasy v0.1.0
go: extracting github.com/bgentry/speakeasy v0.1.0
go: downloading github.com/armon/go-radix v1.0.0
go: extracting github.com/armon/go-radix v1.0.0
go: downloading cloud.google.com/go v0.36.0
go: downloading github.com/spf13/afero v1.2.1
go: downloading github.com/hashicorp/errwrap v1.0.0
go: downloading github.com/oklog/run v1.0.0
go: extracting github.com/oklog/run v1.0.0
go: downloading github.com/mitchellh/reflectwalk v1.0.0
go: extracting github.com/hashicorp/errwrap v1.0.0
go: downloading github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d
go: extracting github.com/mitchellh/reflectwalk v1.0.0
go: downloading github.com/mitchellh/go-homedir v1.0.0
go: extracting github.com/spf13/afero v1.2.1
go: extracting github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d
go: downloading google.golang.org/api v0.1.0
go: downloading github.com/mitchellh/go-testing-interface v1.0.0
go: extracting github.com/mitchellh/go-homedir v1.0.0
go: extracting github.com/mitchellh/go-testing-interface v1.0.0
go: downloading github.com/mitchellh/go-wordwrap v1.0.0
go: extracting github.com/mitchellh/go-wordwrap v1.0.0
go: downloading golang.org/x/net v0.0.0-20190502183928-7f726cade0ab
go: extracting github.com/fatih/color v1.7.0
go: downloading github.com/apparentlymart/go-textseg v1.0.0
go: extracting github.com/apparentlymart/go-textseg v1.0.0
go: downloading github.com/mattn/go-colorable v0.1.1
go: extracting github.com/mattn/go-colorable v0.1.1
go: downloading github.com/zclconf/go-cty-yaml v0.1.0
go: extracting github.com/zclconf/go-cty-yaml v0.1.0
go: extracting google.golang.org/grpc v1.18.0
go: downloading google.golang.org/genproto v0.0.0-20190201180003-4b09977fb922
go: downloading golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734
go: extracting golang.org/x/net v0.0.0-20190502183928-7f726cade0ab
go: downloading github.com/google/go-cmp v0.3.0
go: extracting golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734
go: extracting github.com/google/go-cmp v0.3.0
go: downloading github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb
go: extracting github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb
go: downloading github.com/golang/protobuf v1.3.0
go: downloading github.com/apparentlymart/go-cidr v1.0.0
go: extracting github.com/apparentlymart/go-cidr v1.0.0
go: downloading github.com/blang/semver v3.5.1+incompatible
go: extracting github.com/blang/semver v3.5.1+incompatible
go: extracting cloud.google.com/go v0.36.0
go: extracting github.com/golang/protobuf v1.3.0
go: downloading github.com/mitchellh/copystructure v1.0.0
go: extracting github.com/mitchellh/copystructure v1.0.0
go: extracting google.golang.org/genproto v0.0.0-20190201180003-4b09977fb922
go: downloading go.opencensus.io v0.18.0
go: extracting go.opencensus.io v0.18.0
go: extracting google.golang.org/api v0.1.0
go: extracting github.com/aws/aws-sdk-go v1.19.18
go: downloading github.com/mitchellh/hashstructure v1.0.0
go: downloading github.com/ulikunitz/xz v0.5.5
go: downloading golang.org/x/text v0.3.2
go: downloading golang.org/x/oauth2 v0.0.0-20190220154721-9b3c75971fc9
go: extracting github.com/mitchellh/hashstructure v1.0.0
go: extracting golang.org/x/oauth2 v0.0.0-20190220154721-9b3c75971fc9
go: downloading github.com/googleapis/gax-go v2.0.0+incompatible
go: extracting github.com/googleapis/gax-go v2.0.0+incompatible
go: downloading github.com/googleapis/gax-go/v2 v2.0.3
go: extracting github.com/googleapis/gax-go/v2 v2.0.3
go: downloading golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82
go: extracting github.com/ulikunitz/xz v0.5.5
go: downloading github.com/satori/go.uuid v1.2.0
go: downloading github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af
go: extracting github.com/satori/go.uuid v1.2.0
go: extracting github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af
go: extracting golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82
go: extracting golang.org/x/text v0.3.2
go: finding github.com/hashicorp/terraform v0.12.2
go: finding github.com/ovirt/go-ovirt v4.3.4+incompatible
go: finding github.com/hashicorp/errwrap v1.0.0
go: finding github.com/hashicorp/go-multierror v1.0.0
go: finding github.com/hashicorp/go-hclog v0.0.0-20181001195459-61d530d6c27f
go: finding github.com/davecgh/go-spew v1.1.1
go: finding github.com/hashicorp/hcl2 v0.0.0-20190515223218-4b22149b7cef
go: finding github.com/hashicorp/logutils v1.0.0
go: finding github.com/agext/levenshtein v1.2.2
go: finding github.com/mitchellh/copystructure v1.0.0
go: finding github.com/hashicorp/hil v0.0.0-20190212112733-ab17b08d6590
go: finding github.com/mitchellh/mapstructure v1.1.2
go: finding github.com/hashicorp/go-uuid v1.0.1
go: finding github.com/zclconf/go-cty v0.0.0-20190516203816-4fecf87372ec
go: finding github.com/hashicorp/go-plugin v1.0.1-0.20190610192547-a1bc61569a26
go: finding github.com/apparentlymart/go-textseg v1.0.0
go: finding github.com/hashicorp/go-version v1.1.0
go: finding github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f
go: finding github.com/mitchellh/reflectwalk v1.0.0
go: finding github.com/hashicorp/go-cleanhttp v0.5.0
go: finding github.com/mitchellh/go-wordwrap v1.0.0
go: finding github.com/hashicorp/go-getter v1.3.0
go: finding golang.org/x/text v0.3.2
go: finding github.com/apparentlymart/go-cidr v1.0.0
go: finding golang.org/x/net v0.0.0-20190502183928-7f726cade0ab
go: finding github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
go: finding github.com/blang/semver v3.5.1+incompatible
go: finding github.com/golang/protobuf v1.3.0
go: finding github.com/hashicorp/terraform-config-inspect v0.0.0-20190327195015-8022a2663a70
go: finding google.golang.org/grpc v1.18.0
go: finding github.com/spf13/afero v1.2.1
go: finding github.com/google/go-cmp v0.3.0
go: finding cloud.google.com/go v0.36.0
go: finding github.com/vmihailenco/msgpack v4.0.1+incompatible
go: finding github.com/mitchellh/cli v1.0.0
go: finding github.com/mitchellh/go-homedir v1.0.0
go: finding github.com/zclconf/go-cty-yaml v0.1.0
go: finding github.com/aws/aws-sdk-go v1.19.18
go: finding github.com/mitchellh/hashstructure v1.0.0
go: finding golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734
go: finding github.com/googleapis/gax-go/v2 v2.0.3
go: finding google.golang.org/genproto v0.0.0-20190201180003-4b09977fb922
go: finding github.com/armon/go-radix v1.0.0
go: finding github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d
go: finding google.golang.org/api v0.1.0
go: finding go.opencensus.io v0.18.0
go: finding github.com/bgentry/speakeasy v0.1.0
go: finding github.com/fatih/color v1.7.0
go: finding github.com/hashicorp/go-safetemp v1.0.0
go: finding github.com/mattn/go-isatty v0.0.5
go: finding github.com/posener/complete v1.2.1
go: finding github.com/mitchellh/go-testing-interface v1.0.0
go: finding golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82
go: finding github.com/ulikunitz/xz v0.5.5
go: finding github.com/mattn/go-colorable v0.1.1
go: finding github.com/satori/go.uuid v1.2.0
go: finding github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af
go: finding golang.org/x/oauth2 v0.0.0-20190220154721-9b3c75971fc9
go: finding github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb
go: finding github.com/oklog/run v1.0.0

Check created binary file.

$ ls $GOPATH/bin/terraform-provider-ovirt
/home/jmutai/go/bin/terraform-provider-ovirt

Step 4: Using the oVirt terraform provider

Create terraform providers directory:

mkdir ~/.terraform.d/plugins

Copy provider binary file to created plugins directory.

cp $GOPATH/bin/terraform-provider-ovirt ~/.terraform.d/plugins

For creation of resources on your oVirt/RHEV environment, refer to:

How To Provision VMs on oVirt / RHEV with Terraform

The basic unit is the creation of provider configuration file

$ vim main.tf

provider "ovirt" {
  username = "[email protected]"
  url      = "https://ovirt/ovirt-engine/api"
  password = "Password"
}

The following arguments are supported:

  • url – (Required) The oVirt engine API URL. If omitted, the OVIRT_URL environment variable is used.
  • 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.

After placing creating the file, run the following command to initialize it.

$ 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.

More guides:

Deploy VM Instances on Hetzner Cloud with Terraform

How To Provision VMs on KVM with Terraform

Install a Server or Virtual Machine from ISO on oVirt / RHEV

Create and Manage User Accounts on oVirt and RHEV