/terraform-provider-libvirt

(EXPERIMENTAL) terraform provider for libvirt

Primary LanguageGoApache License 2.0Apache-2.0

Terraform provider for libvirt

experimental Build Status

This provider is still experimental/in development. To see what is left or planned, see the issues list.

This is a terraform provider that lets you provision servers on a libvirt host via Terraform.

Installing

Copied from the Terraform documentation:

To install a plugin, put the binary somewhere on your filesystem, then configure Terraform to be able to find it. The configuration where plugins are defined is ~/.terraformrc for Unix-like systems and %APPDATA%/terraform.rc for Windows.

The binary should be renamed to terraform-provider-libvirt

You should update your .terraformrc and refer to the binary:

providers {
  libvirt = "/path/to/terraform-provider-libvirt"
}

Using the provider

Here is an example that will setup the following:

  • A virtual server resource

(create this as libvirt.tf and run terraform commands from this directory):

provider "libvirt" {
    uri = "qemu:///system"
}

You can also set the URI in the LIBVIRT_DEFAULT_URI environment variable.

Now, define a libvirt domain:

resource "libvirt_domain" "terraform_test" {
  name = "terraform_test"
}

Now you can see the plan, apply it, and then destroy the infrastructure:

$ terraform plan
$ terraform apply
$ terraform destroy

Building from source

  1. Install Go on your machine
  2. Set up Gopath
  3. git clone this repository into $GOPATH/src/github.com/dmacvicar/terraform-provider-libvirt
  4. Run go get to get dependencies
  5. Run go install to build the binary. You will now find the binary at $GOPATH/bin/terraform-provider-libvirt.

Running

  1. create the example file libvirt.tf in your working directory
  2. terraform plan
  3. terraform apply

Running acceptance tests

You need to define the LIBVIRT_DEFAULT_URI and TF_ACC variables:

export LIBVIRT_DEFAULT_URI=qemu:///system
export TF_ACC=1
go test ./...

Known Problems

  • There is a bug in libvirt that seems to be causing problems to unlink volumes. Tracked here.

    If you see something like:

    cannot unlink file '/var/lib/libvirt/images/XXXXXXXXXXXX': Permission denied

    It is probably related.

Author

The structure and boilerplate is inspired from the Softlayer and Google Terraform provider sources.

License

  • Apache 2.0, See LICENSE file