Terraform provider to provision infrastructure with Linux's KVM using libvirt
Go to file
Egbert Eich d41792ab15
if no machine is set, use default types depending on the arch (#1014)
* Improve 'machine' type selection

If no machine is set, use default types depending on the arch.
The selection is taken from https://github.com/virt-manager/virt-manager
file virtinst/guest.py function get_recommended_machine().

Signed-off-by: Egbert Eich <eich@suse.com>

* Test for getMachineTypeForArch()

Signed-off-by: Egbert Eich <eich@suse.com>

---------

Signed-off-by: Egbert Eich <eich@suse.com>
2024-03-22 00:23:42 +01:00
.github ci: upgrade golangci-lint in workflows (#1061) 2023-12-28 14:31:09 +01:00
contrib Fixing spelling mistakes and small grammar errors as well 2019-09-04 11:08:06 -04:00
docs Minor cleanup of migration-13 doc 2021-01-24 09:03:31 +11:00
examples Examples update (#927) 2024-03-22 00:21:18 +01:00
libvirt if no machine is set, use default types depending on the arch (#1014) 2024-03-22 00:23:42 +01:00
travis Remove unused script 2020-10-10 14:54:14 +02:00
version refactor code to start getting rid of resource exist functions 2023-01-01 13:30:14 +01:00
website cleanup spurious character 2024-03-19 22:41:15 +01:00
.gitignore Add .terraform to .gitignore 2020-11-08 12:11:04 +01:00
.golangci.yaml update build settings and linters 2023-11-20 00:02:29 +01:00
.goreleaser.yml remove version flag 2022-12-29 02:22:52 +01:00
.readthedocs.yml Fix readthedocs config format key (2nd attempt) 2019-10-09 17:07:25 +02:00
.travis.yml Remove mod=vendor from .travis.yml 2020-11-11 21:51:33 +01:00
CHANGELOG.md update changelog to reflect release v0.5.1 2019-01-07 13:13:10 +01:00
CONTRIBUTING.md CONTRIBUTING.md: process for schema changes 2020-10-10 16:45:56 +02:00
LICENSE import 2016-02-27 22:45:16 +01:00
Makefile Fix `test` make target to run all tests (#1034) 2023-09-25 20:30:32 +02:00
README.md fix typos 2023-11-19 23:34:08 +01:00
go.mod Bump google.golang.org/grpc from 1.51.0 to 1.56.3 (#1043) 2023-12-28 14:32:48 +01:00
go.sum Bump google.golang.org/grpc from 1.51.0 to 1.56.3 (#1043) 2023-12-28 14:32:48 +01:00
main.go remove version flag 2022-12-29 02:22:52 +01:00
tools.go Cleanup Makefile 2019-02-17 20:00:17 +01:00

README.md

Terraform provider for libvirt

alpha Tests Registry


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

Introduction & Goals

This project exists:

  • To allow teams to get the benefits Software Defined Infrastructure Terraform provides, on top of classical and cheap virtualization infrastructure provided by Linux and KVM This helps in very dynamic DevOps, Development and Testing activities.
  • To allow for mixing KVM resources with other infrastructure Terraform is able to manage

What is NOT in scope:

  • To support every advanced feature libvirt supports

    This would make the mapping from terraform complicated and not maintainable. See the How to contribute section to understand how to approach new features.

Getting started

The provider is available for auto-installation from the Terraform Registry.

In your main.tf file, specify the version you want to use:

terraform {
  required_providers {
    libvirt = {
      source = "dmacvicar/libvirt"
    }
  }
}

provider "libvirt" {
  # Configuration options
}

And now run terraform init:

$ terraform init

Creating your first virtual machine

Here is an example that will setup the following:

  • A virtual server resource

(create this as main.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 init
$ terraform plan
$ terraform apply
$ terraform destroy

Look at more advanced examples here and check the documentation.

Manual installation

You can also manually download the provider from the releases section on Github. To install it, refer to the Terraform documentation.

Building from source

  • Go is required for building.
git clone https://github.com/dmacvicar/terraform-provider-libvirt.git
cd terraform-provider-libvirt
make

The binary will be called terraform-provider-libvirt.

Using multiple hypervisors / provider instances

You can target different libvirt hosts instantiating the provider multiple times. Example.

Using qemu-agent

From its documentation, qemu-agent:

It is a daemon program running inside the domain which is supposed to help management applications with executing functions which need assistance of the guest OS.

Until terraform-provider-libvirt 0.4.2, qemu-agent was used by default to get network configuration. However, if qemu-agent is not running, this creates a delay until connecting to it times-out.

In current versions, we default to not to attempt connecting to it, and attempting to retrieve network interface information from the agent needs to be enabled explicitly with qemu_agent = true, further details here. Note that you still need to make sure the agent is running in the OS, and that is unrelated to this option.

Note: when using bridge network configurations you need to enable the qemu_agent = true. otherwise you will not retrieve the ip addresses of domains.

Be aware that this variables may be subject to change again in future versions.

Upstream projects using terraform-libvirt:

Authors

See also the list of contributors who participated in this project.

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

License

  • Apache 2.0, See LICENSE file