From 9230dabd7a22616118e73e9c1566bb218ffdaef7 Mon Sep 17 00:00:00 2001 From: Rene Gielen Date: Sun, 18 Oct 2020 10:54:31 +0200 Subject: [PATCH 01/12] Add terraform-libvirt provider module --- provider/libvirt/main.tf | 211 ++++++++++++++++++ provider/libvirt/templates/cloud_init.cfg | 22 ++ provider/libvirt/templates/network_config.cfg | 11 + provider/libvirt/versions.tf | 9 + 4 files changed, 253 insertions(+) create mode 100644 provider/libvirt/main.tf create mode 100644 provider/libvirt/templates/cloud_init.cfg create mode 100644 provider/libvirt/templates/network_config.cfg create mode 100644 provider/libvirt/versions.tf diff --git a/provider/libvirt/main.tf b/provider/libvirt/main.tf new file mode 100644 index 0000000..d02da2a --- /dev/null +++ b/provider/libvirt/main.tf @@ -0,0 +1,211 @@ +variable "hosts" { + default = 3 +} + +variable "disk_size_gb" { + default = 50 +} + +variable "memory_mb" { + default = 1024 +} + +variable "vcpus" { + default = 1 +} + +variable "image_source" { + type = string + default = "https://cloud-images.ubuntu.com/releases/bionic/release-20200922/ubuntu-18.04-server-cloudimg-amd64.img" + # 2020-10-18: Lastest release 20201014 has issues with booting +} + +variable "basename" { + type = string + default = "hobbykube" +} + +variable "ssh_keys" { + type = list + default = [] +} + +variable "ssh_keys_github_username" { + default = "" +} + +variable "apt_packages" { + type = list + default = [] +} + +variable "do_package_upgrade" { + type = string + default = "false" +} + +variable "hostname_format" { + type = string + default = "kube%d" +} + +variable "libvirt_connection_uri" { + type = string + default = "qemu:///system" +} + +variable "public_gateway" { + type = string + default = "" +} + +variable "public_nameserver" { + type = string + default = "" +} + +variable "public_iprange" { + type = string + default = "" +} + +variable "public_iprange_offset" { + default = 1 +} + +locals { + user_data = [ + for n in range(var.hosts) : templatefile("${path.module}/templates/cloud_init.cfg", { + hostname = element(data.template_file.hostnames.*.rendered, n) + keys = var.ssh_keys_github_username == "" ? var.ssh_keys : data.github_user.ssh_keys_user.ssh_keys + do_upgrade = var.do_package_upgrade + }) + ] +} + +provider "libvirt" { + uri = var.libvirt_connection_uri +} + +resource "libvirt_pool" "storage_pool" { + name = "${var.basename}-pool" + type = "dir" + path = "/var/lib/libvirt/images/${var.basename}-pool" +} + +resource "libvirt_volume" "os_image" { + name = "${var.basename}-baseimage-ubuntu-qcow2" + pool = libvirt_pool.storage_pool.name + source = var.image_source + format = "qcow2" +} + +resource "libvirt_volume" "volume" { + count = var.hosts + name = "${var.basename}-volume-${element(data.template_file.hostnames.*.rendered, count.index)}" + pool = libvirt_pool.storage_pool.name + base_volume_id = libvirt_volume.os_image.id + size = var.disk_size_gb * 1024 * 1024 * 1024 +} + +resource "libvirt_cloudinit_disk" "commoninit" { + count = var.hosts + name = "${element(data.template_file.hostnames.*.rendered, count.index)}-commoninit.iso" + user_data = element(local.user_data, count.index) + network_config = element(data.template_file.network_config.*.rendered, count.index) + pool = libvirt_pool.storage_pool.name +} + +resource "libvirt_domain" "node_domain" { + count = var.hosts + name = "${var.basename}-${element(data.template_file.hostnames.*.rendered, count.index)}" + memory = var.memory_mb + vcpu = var.vcpus + + cloudinit = element(libvirt_cloudinit_disk.commoninit.*.id, count.index) + + network_interface { + bridge = "br0" + } + + # IMPORTANT: this is a known bug on cloud images, since they expect a console + # we need to pass it + # https://bugs.launchpad.net/cloud-images/+bug/1573095 + console { + type = "pty" + target_port = "0" + target_type = "serial" + } + + console { + type = "pty" + target_type = "virtio" + target_port = "1" + } + + disk { + volume_id = element(libvirt_volume.volume.*.id, count.index) + } + + graphics { + type = "spice" + listen_type = "address" + autoport = true + } + + connection { + user = "root" + type = "ssh" + timeout = "2m" + host = element(data.template_file.public_ips.*.rendered, count.index) + } + + provisioner "remote-exec" { + inline = [ + "cloud-init status --wait > /dev/null 2>&1", + "DEBIAN_FRONTEND=noninteractive apt-get install -yq ufw ${join(" ", var.apt_packages)}", + ] + } + +} + +data "github_user" "ssh_keys_user" { + username = var.ssh_keys_github_username == "" ? "github" : var.ssh_keys_github_username +} + +data "template_file" "public_ips" { + count = var.hosts + template = "$${ip}" + + vars = { + ip = cidrhost(var.public_iprange, count.index + var.public_iprange_offset) + } +} + +data "template_file" "hostnames" { + count = var.hosts + template = "$${name}" + + vars = { + name = format(var.hostname_format, count.index + 1) + } +} + +data "template_file" "network_config" { + count = var.hosts + template = file("${path.module}/templates/network_config.cfg") + + vars = { + address = element(data.template_file.public_ips.*.rendered, count.index) + gateway = var.public_gateway + nameserver = var.public_nameserver + } +} + +output "public_ips" { + value = "${data.template_file.public_ips.*.rendered}" +} + +output "private_ips" { + value = "${data.template_file.public_ips.*.rendered}" +} diff --git a/provider/libvirt/templates/cloud_init.cfg b/provider/libvirt/templates/cloud_init.cfg new file mode 100644 index 0000000..f2494f2 --- /dev/null +++ b/provider/libvirt/templates/cloud_init.cfg @@ -0,0 +1,22 @@ +#cloud-config +hostname: ${hostname} + +package_update: true +package_upgrade: ${do_upgrade} + +growpart: + mode: auto + devices: ["/"] + ignore_growroot_disabled: false + +ssh_pwauth: True + +users: +- name: root + ssh_authorized_keys: +%{ for key in keys } + - ${key} +%{ endfor ~} + +packages: + - qemu-guest-agent diff --git a/provider/libvirt/templates/network_config.cfg b/provider/libvirt/templates/network_config.cfg new file mode 100644 index 0000000..e4e5007 --- /dev/null +++ b/provider/libvirt/templates/network_config.cfg @@ -0,0 +1,11 @@ +version: 2 +ethernets: + ens3: + dhcp4: no + dhcp6: no + addresses: + - ${address}/24 + gateway4: ${gateway} + nameservers: + addresses: + - ${nameserver} diff --git a/provider/libvirt/versions.tf b/provider/libvirt/versions.tf new file mode 100644 index 0000000..ece98a4 --- /dev/null +++ b/provider/libvirt/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 0.13" + required_providers { + libvirt = { + source = "dmacvicar/libvirt" + version = "0.6.2" + } + } +} From eb7e067864d9667f83f2259b57fc096dda144f3c Mon Sep 17 00:00:00 2001 From: Rene Gielen Date: Sun, 18 Oct 2020 11:17:05 +0200 Subject: [PATCH 02/12] Add global variables for libvirt provider --- variables.tf | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/variables.tf b/variables.tf index 101e44e..531ea83 100644 --- a/variables.tf +++ b/variables.tf @@ -115,6 +115,68 @@ variable "packet_user_data" { default = "" } +/* libvirt */ +variable "libvirt_disk_size_gb" { + default = 50 +} + +variable "libvirt_memory_mb" { + default = 1024 +} + +variable "libvirt_vcpus" { + default = 1 +} + +variable "libvirt_image_source" { + type = string + default = "https://cloud-images.ubuntu.com/releases/bionic/release-20200922/ubuntu-18.04-server-cloudimg-amd64.img" + # 2020-10-18: Lastest release 20201014 has issues with booting +} + +variable "libvirt_basename" { + type = string + default = "hobbykube" +} + +variable "libvirt_ssh_keys" { + type = list + default = [] +} + +variable "libvirt_sh_keys_github_username" { + default = "" +} + +variable "libvirt_do_package_upgrade" { + type = string + default = "false" +} + +variable "libvirt_connection_uri" { + type = string + default = "qemu:///system" +} + +variable "libvirt_public_gateway" { + type = string + default = "" +} + +variable "libvirt_public_nameserver" { + type = string + default = "" +} + +variable "libvirt_public_iprange" { + type = string + default = "" +} + +variable "libvirt_public_iprange_offset" { + default = 1 +} + /* aws dns */ variable "aws_access_key" { default = "" From 2b2b8ecf0966e87ec85f342db557e277fc507b74 Mon Sep 17 00:00:00 2001 From: Rene Gielen Date: Sun, 18 Oct 2020 11:19:09 +0200 Subject: [PATCH 03/12] Set default host count to 0 --- provider/libvirt/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provider/libvirt/main.tf b/provider/libvirt/main.tf index d02da2a..5dc05c9 100644 --- a/provider/libvirt/main.tf +++ b/provider/libvirt/main.tf @@ -1,5 +1,5 @@ variable "hosts" { - default = 3 + default = 0 } variable "disk_size_gb" { From 50b5efd216dbbae1772643713223db0a43af8293 Mon Sep 17 00:00:00 2001 From: Rene Gielen Date: Sun, 18 Oct 2020 11:20:41 +0200 Subject: [PATCH 04/12] Add module section for libvirt provider --- main.tf | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/main.tf b/main.tf index cb68076..bf7723b 100644 --- a/main.tf +++ b/main.tf @@ -79,6 +79,27 @@ module "provider" { # ssh_keys = var.upcloud_ssh_keys # } +# module "provider" { +# source = "./provider/libvirt" +# +# disk_size_gb = var.libvirt_disk_size_gb +# memory_mb = var.libvirt_memory_mb +# vcpus = var.libvirt_vcpus +# image_source = var.libvirt_image_source +# basename = var.libvirt_basename +# ssh_keys = var.libvirt_ssh_keys +# ssh_keys_github_username = var.libvirt_ssh_keys_github_username +# do_package_upgrade = var.libvirt_do_package_upgrade +# hostname_format = var.libvirt_hostname_format +# libvirt_connection_uri = var.libvirt_libvirt_connection_uri +# public_gateway = var.libvirt_public_gateway +# public_nameserver = var.libvirt_public_nameserver +# public_iprange = var.libvirt_public_iprange +# public_iprange_offset = var.libvirt_public_iprange_offset +# hosts = var.node_count +# hostname_format = var.hostname_format +# } + module "swap" { source = "./service/swap" From e03f233f100604c65a45da455b3c3164511231e7 Mon Sep 17 00:00:00 2001 From: Rene Gielen Date: Sun, 18 Oct 2020 11:30:43 +0200 Subject: [PATCH 05/12] Fix variable name typo --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index 531ea83..ede6a4a 100644 --- a/variables.tf +++ b/variables.tf @@ -144,7 +144,7 @@ variable "libvirt_ssh_keys" { default = [] } -variable "libvirt_sh_keys_github_username" { +variable "libvirt_ssh_keys_github_username" { default = "" } From 1e01f1d0c22a6b3291b3e5a700577d2f1cd294e4 Mon Sep 17 00:00:00 2001 From: Rene Gielen Date: Sun, 18 Oct 2020 11:31:56 +0200 Subject: [PATCH 06/12] Add missing outputs --- provider/libvirt/main.tf | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/provider/libvirt/main.tf b/provider/libvirt/main.tf index 5dc05c9..df039de 100644 --- a/provider/libvirt/main.tf +++ b/provider/libvirt/main.tf @@ -202,6 +202,10 @@ data "template_file" "network_config" { } } +output "hostnames" { + value = "${template_file.hostnames.*.rendered}" +} + output "public_ips" { value = "${data.template_file.public_ips.*.rendered}" } @@ -209,3 +213,7 @@ output "public_ips" { output "private_ips" { value = "${data.template_file.public_ips.*.rendered}" } + +output "private_network_interface" { + value = "ens3" +} From a0703a5e7d89bb3bf784655482de437433fe9770 Mon Sep 17 00:00:00 2001 From: Rene Gielen Date: Sun, 18 Oct 2020 15:19:35 +0200 Subject: [PATCH 07/12] Add explicit dependencies for output variables --- provider/libvirt/main.tf | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/provider/libvirt/main.tf b/provider/libvirt/main.tf index df039de..6c78179 100644 --- a/provider/libvirt/main.tf +++ b/provider/libvirt/main.tf @@ -16,8 +16,7 @@ variable "vcpus" { variable "image_source" { type = string - default = "https://cloud-images.ubuntu.com/releases/bionic/release-20200922/ubuntu-18.04-server-cloudimg-amd64.img" - # 2020-10-18: Lastest release 20201014 has issues with booting + default = "https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.img" } variable "basename" { @@ -36,7 +35,9 @@ variable "ssh_keys_github_username" { variable "apt_packages" { type = list - default = [] + default = [ + "net-tools", + ] } variable "do_package_upgrade" { @@ -117,12 +118,12 @@ resource "libvirt_cloudinit_disk" "commoninit" { } resource "libvirt_domain" "node_domain" { - count = var.hosts - name = "${var.basename}-${element(data.template_file.hostnames.*.rendered, count.index)}" - memory = var.memory_mb - vcpu = var.vcpus + count = var.hosts + name = "${var.basename}-${element(data.template_file.hostnames.*.rendered, count.index)}" + memory = var.memory_mb + vcpu = var.vcpus - cloudinit = element(libvirt_cloudinit_disk.commoninit.*.id, count.index) + cloudinit = element(libvirt_cloudinit_disk.commoninit.*.id, count.index) network_interface { bridge = "br0" @@ -203,17 +204,29 @@ data "template_file" "network_config" { } output "hostnames" { - value = "${template_file.hostnames.*.rendered}" + value = "${data.template_file.hostnames.*.rendered}" + depends_on = [ + libvirt_domain.node_domain, + ] } output "public_ips" { value = "${data.template_file.public_ips.*.rendered}" + depends_on = [ + libvirt_domain.node_domain, + ] } output "private_ips" { value = "${data.template_file.public_ips.*.rendered}" + depends_on = [ + libvirt_domain.node_domain, + ] } output "private_network_interface" { value = "ens3" + depends_on = [ + libvirt_domain.node_domain, + ] } From 11e34a174b7ce42f2ee04d1d168dba666ee8ee97 Mon Sep 17 00:00:00 2001 From: Rene Gielen Date: Sun, 18 Oct 2020 15:25:13 +0200 Subject: [PATCH 08/12] Switch to Ubuntu 20.04 cloud image URL --- variables.tf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/variables.tf b/variables.tf index ede6a4a..6f4f3c1 100644 --- a/variables.tf +++ b/variables.tf @@ -130,8 +130,7 @@ variable "libvirt_vcpus" { variable "libvirt_image_source" { type = string - default = "https://cloud-images.ubuntu.com/releases/bionic/release-20200922/ubuntu-18.04-server-cloudimg-amd64.img" - # 2020-10-18: Lastest release 20201014 has issues with booting + default = "https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.img" } variable "libvirt_basename" { From 50352c081bf90884fc477cc681c20a203a569299 Mon Sep 17 00:00:00 2001 From: Rene Gielen Date: Sun, 18 Oct 2020 15:29:13 +0200 Subject: [PATCH 09/12] Fix redundant and broken variable initialization --- main.tf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.tf b/main.tf index bf7723b..713bfb6 100644 --- a/main.tf +++ b/main.tf @@ -90,8 +90,7 @@ module "provider" { # ssh_keys = var.libvirt_ssh_keys # ssh_keys_github_username = var.libvirt_ssh_keys_github_username # do_package_upgrade = var.libvirt_do_package_upgrade -# hostname_format = var.libvirt_hostname_format -# libvirt_connection_uri = var.libvirt_libvirt_connection_uri +# libvirt_connection_uri = var.libvirt_connection_uri # public_gateway = var.libvirt_public_gateway # public_nameserver = var.libvirt_public_nameserver # public_iprange = var.libvirt_public_iprange From 4ce05fa7d780e1c445946eddbb2112520b616ac5 Mon Sep 17 00:00:00 2001 From: Rene Gielen Date: Sun, 18 Oct 2020 17:49:01 +0200 Subject: [PATCH 10/12] Create README with prerequisites --- provider/libvirt/README.md | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 provider/libvirt/README.md diff --git a/provider/libvirt/README.md b/provider/libvirt/README.md new file mode 100644 index 0000000..651e650 --- /dev/null +++ b/provider/libvirt/README.md @@ -0,0 +1,53 @@ +# libvirt Provisioner + +[Terraform provider for libvirt](https://github.com/dmacvicar/terraform-provider-libvirt) is a non-official Terraform provider to provision KVM/QEMU based virtual machines. +This module integrates the libvirt provider with hobby-kube. + +## Prerequisites + +First of all, a working KVM / QEMU host is needed. +The module works both on the same host as well as on a machine with `qemu+ssh`-access to a host machine. +Some installations have to be made on the machine that is used for Terraform provisioning: + +* terraform-provider-libvirt +* mkisofs + +### Linux + +[Download a suitable terraform-provider-libvirt release](https://github.com/dmacvicar/terraform-provider-libvirt/releases) and extract the binary. +Once the binary is extracted, it can be placed in the user's Terraform plugins cache: + +``` +export TERRAFORM_LIBVIRT_VERSION="0.6.2" +mkdir -p ~/.local/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/$TERRAFORM_LIBVIRT_VERSION/linux_amd64 +cp terraform-provider-libvirt ~/.local/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/$TERRAFORM_LIBVIRT_VERSION/linux_amd64 +``` + +More information on how to install the provider for Terraform >= 0.13 can be found [here](https://github.com/dmacvicar/terraform-provider-libvirt/blob/master/docs/migration-13.md). + +`mkisofs` is also needed. +On Ubuntu it can be installed with + +``` +sudo apt install genisoimage +``` + +### MacOS + +There is no pre-compiled binary for terraform-provider-libvirt for MacOS. +Instead, it can be [built from source](https://github.com/dmacvicar/terraform-provider-libvirt#building-from-source). + +Similar to Linux, the resulting binary needs to be placed in the user's terraform plugin cache directory: + +``` +export TERRAFORM_LIBVIRT_VERSION="0.6.2" +mkdir -p ~/.local/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/$TERRAFORM_LIBVIRT_VERSION/darwin_amd64 +cp terraform-provider-libvirt ~/.local/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/$TERRAFORM_LIBVIRT_VERSION/darwin_amd64 +``` + +`mkisofs` is also needed. +It comes with `cdrtools`, which can be installed with Homebrew: + +``` +brew install cdrtools +``` From 93b99bfe863198b8a4eb8753069187703b685842 Mon Sep 17 00:00:00 2001 From: Rene Gielen Date: Sun, 18 Oct 2020 21:55:10 +0200 Subject: [PATCH 11/12] Complete libvirt provider documentation and examples --- provider/libvirt/README.md | 41 +++++++++++++++++-- provider/libvirt/terraform.tfvars.example | 48 +++++++++++++++++++++++ 2 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 provider/libvirt/terraform.tfvars.example diff --git a/provider/libvirt/README.md b/provider/libvirt/README.md index 651e650..d69315c 100644 --- a/provider/libvirt/README.md +++ b/provider/libvirt/README.md @@ -5,9 +5,9 @@ This module integrates the libvirt provider with hobby-kube. ## Prerequisites -First of all, a working KVM / QEMU host is needed. -The module works both on the same host as well as on a machine with `qemu+ssh`-access to a host machine. -Some installations have to be made on the machine that is used for Terraform provisioning: +First of all, a working KVM / QEMU host with bridged networking is needed. +The module works both when provisioned from the virtualization host as well as on a machine with `qemu+ssh`-access to a host machine. +Some installations have to be made **on the machine that is used for Terraform provisioning**: * terraform-provider-libvirt * mkisofs @@ -51,3 +51,38 @@ It comes with `cdrtools`, which can be installed with Homebrew: ``` brew install cdrtools ``` + +## Usage and Configuration + +Uncomment the libvirt-provider module in the top-level `main.tf` file. +Configure your desired setup in `terraform.tfvars`. + +See provided `terraform.tfvars.example` for possible options and explanations. + +### Network Setup + +For now, only bridged networking is supported. +Bridge `br0` must be provisioned on the virtualization host. + +Nodes will be provisioned with static IP Addresses within the given briged network. +Given your bridged network is `192.168.100.0/24`, a minimim viable configuration with three hosts and IP addresses counted from `192.168.100.120` looks like this: + +``` +# Count of nodes to provide (must be provided) +node_count = 3 + +# Range of IPs in the bridged host network to use for provisioning +# (must be provided) +libvirt_public_iprange = "192.168.100.0/24" + +# Offset in public ip range to start with when providing node IPs (default: 1) +libvirt_public_iprange_offset = 120 + +# The gateway for the node to use +# (must be provided) +libvirt_public_gateway = "192.168.100.1" + +# The nameserver for the node to use +# (must be provided) +libvirt_public_nameserver = "192.168.100.1" +``` diff --git a/provider/libvirt/terraform.tfvars.example b/provider/libvirt/terraform.tfvars.example new file mode 100644 index 0000000..4c719a9 --- /dev/null +++ b/provider/libvirt/terraform.tfvars.example @@ -0,0 +1,48 @@ +# Count of nodes to provide (must be provided) +node_count = 3 + +# Range of IPs in the bridged host network to use for provisioning +# (must be provided) +libvirt_public_iprange = "192.168.100.0/24" + +# Offset in public ip range to start with when providing node IPs (default: 1) +libvirt_public_iprange_offset = 120 + +# The gateway for the node to use +# (must be provided) +libvirt_public_gateway = "192.168.100.1" + +# The nameserver for the node to use +# (must be provided) +libvirt_public_nameserver = "192.168.100.1" + +# Connection URL for libvirt provider (default: "qemu:///system") +libvirt_connection_uri = "qemu+ssh://root@kvmhost.some.net/system?socket=/var/run/libvirt/libvirt-sock" + +# Size of virtual disk per node in GB (default: 50) +libvirt_disk_size_gb = 30 + +# Memory per node in MB (default: 1024) +libvirt_memory_mb = 2048 + +# Number of CPUs per node (default: 1) +libvirt_vcpus = 2 + +# Cloud image source +# Default: "https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.img" +# An image may be downladed to the providing machine and referenced as a local file, as shown below +libvirt_image_source = "ubuntu-20.04-server-cloudimg-amd64.img" + +# The basename for storage pool and volumes (default: "hobbykube") +libvirt_basename = "k8scluster" + +# GitHub user to import ssh keys from (default: "") +# Will take precedence over libvirt_ssh_keys, when given +libvirt_ssh_keys_github_username = "johndoe" + +# List of directly provided ssh public keys +# Will only be picked up when no libvirt_ssh_keys_github_username is given +# libvirt_ssh_keys = ["ssh-dss ....",] + +# Should apt-get upgrade be performed? (default: "false") +libvirt_do_package_upgrade = "true" From dd8688685d12d58003dfb7740708647aa30a2e22 Mon Sep 17 00:00:00 2001 From: Rene Gielen Date: Tue, 20 Oct 2020 10:31:37 +0200 Subject: [PATCH 12/12] Enhance libvirt module docs to cover libvirt installation and fix mac plugin setup --- provider/libvirt/README.md | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/provider/libvirt/README.md b/provider/libvirt/README.md index d69315c..a6ba001 100644 --- a/provider/libvirt/README.md +++ b/provider/libvirt/README.md @@ -6,14 +6,21 @@ This module integrates the libvirt provider with hobby-kube. ## Prerequisites First of all, a working KVM / QEMU host with bridged networking is needed. -The module works both when provisioned from the virtualization host as well as on a machine with `qemu+ssh`-access to a host machine. +The module works both when provisioned from the virtualization host as well as on a machine with proper `qemu+ssh`-access to a host machine. Some installations have to be made **on the machine that is used for Terraform provisioning**: +* libvirt * terraform-provider-libvirt * mkisofs ### Linux +[Libvirt](https://libvirt.org/) needs to be installed to communicate with the Linux virtualization host, if the provisioning machine is not the host as well. +On Ubuntu this can be done with +``` +sudo apt-get install libvirt-clients +``` + [Download a suitable terraform-provider-libvirt release](https://github.com/dmacvicar/terraform-provider-libvirt/releases) and extract the binary. Once the binary is extracted, it can be placed in the user's Terraform plugins cache: @@ -34,15 +41,21 @@ sudo apt install genisoimage ### MacOS +[Libvirt](https://libvirt.org/) needs to be installed to communicate with the Linux virtualization host. +This can be done with Homebrew: +``` +brew install libvirt +``` + There is no pre-compiled binary for terraform-provider-libvirt for MacOS. Instead, it can be [built from source](https://github.com/dmacvicar/terraform-provider-libvirt#building-from-source). -Similar to Linux, the resulting binary needs to be placed in the user's terraform plugin cache directory: +Similar to Linux, the resulting binary needs to be placed in the [user's terraform plugin cache directory](https://www.terraform.io/docs/commands/cli-config.html#provider-installation): ``` export TERRAFORM_LIBVIRT_VERSION="0.6.2" -mkdir -p ~/.local/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/$TERRAFORM_LIBVIRT_VERSION/darwin_amd64 -cp terraform-provider-libvirt ~/.local/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/$TERRAFORM_LIBVIRT_VERSION/darwin_amd64 +mkdir -p ~/Library/Application\ Support/io.terraform/plugins/registry.terraform.io/dmacvicar/libvirt/$TERRAFORM_LIBVIRT_VERSION/darwin_amd64 +cp terraform-provider-libvirt ~/Library/Application\ Support/io.terraform/plugins/registry.terraform.io/dmacvicar/libvirt/$TERRAFORM_LIBVIRT_VERSION/darwin_amd64 ``` `mkisofs` is also needed. @@ -57,7 +70,7 @@ brew install cdrtools Uncomment the libvirt-provider module in the top-level `main.tf` file. Configure your desired setup in `terraform.tfvars`. -See provided `terraform.tfvars.example` for possible options and explanations. +See the provided `terraform.tfvars.example` file in the module directory for possible options and explanations. ### Network Setup