Skip to content

Commit 5545c22

Browse files
author
Jim Crowley
authored
Merge branch 'master' into contrib_examples
2 parents b276e79 + 816efbf commit 5545c22

File tree

14 files changed

+313
-32
lines changed

14 files changed

+313
-32
lines changed

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ Follow the instructions for your distribution:
5858

5959
## Building from source
6060

61-
Before building, you will need the following
61+
### Requirements
62+
63+
- [Terraform](https://www.terraform.io/downloads.html)
64+
- [Go](https://golang.org/doc/install) (to build the provider plugin)
65+
- [libvirt](https://libvirt.org/downloads.html) 1.2.14 or newer development headers
66+
- `cgo` is required by the [libvirt-go](https://github.com/libvirt/libvirt-go) package. `export CGO_ENABLED="1"`
6267

63-
* libvirt 1.2.14 or newer development headers
64-
* latest [golang](https://golang.org/dl/) version
65-
* `cgo` is required by the [libvirt-go](https://github.com/libvirt/libvirt-go) package. `export CGO_ENABLED="1"`
6668

6769
This project uses [go modules](https://github.com/golang/go/wiki/Modules) to vendor all its
6870
dependencies.
@@ -74,8 +76,18 @@ takes advantage of features available only inside of the latest stable release.
7476

7577
You need also need libvirt-dev(el) package installed.
7678

79+
### Building The Provider
80+
81+
Clone repository to: `$GOPATH/src/github.com/dmacvicar/terraform-provider-libvirt`
82+
83+
```console
84+
mkdir -p $GOPATH/src/github.com/dmacvicar; cd $GOPATH/src/github.com/dmacvicar
85+
git clone https://github.com/dmacvicar/terraform-provider-libvirt.git
86+
```
87+
88+
Enter the provider directory and build the provider
89+
7790
```console
78-
go get github.com/dmacvicar/terraform-provider-libvirt
7991
cd $GOPATH/src/github.com/dmacvicar/terraform-provider-libvirt
8092
make install
8193
```
@@ -163,6 +175,9 @@ Be aware that this variables may be subject to change again in future versions.
163175
* [sumaform](https://github.com/moio/sumaform)
164176
sumaform is a way to quickly configure, deploy, test [Uyuni](https://www.uyuni-project.org/) and [SUSE Manager](https://www.suse.com/products/suse-manager/) setups with clients and servers.
165177

178+
* [ha-cluster-sap](https://github.com/SUSE/ha-sap-terraform-deployments)
179+
Automated HA and SAP Deployments in Public/Private Clouds (including Libvirt/KVM)
180+
166181
* [ceph-open-terrarium](https://github.com/MalloZup/ceph-open-terrarium)
167182
ceph-open-terrarium is a way to quickly configure, deploy, tests CEPH cluster without or with [Deepsea](https://github.com/SUSE/DeepSea)
168183

@@ -172,6 +187,10 @@ Be aware that this variables may be subject to change again in future versions.
172187
* [Community Driven Docker Examples](contrib/)
173188
Docker examples showing how to use the Libvirt Provider
174189

190+
* [Openshift 4 Installer](https://github.com/openshift/installer)
191+
The Openshift 4 Installer uses Terraform for cluster orchestration and relies on terroform-provider-libvirt for
192+
libvirt platform.
193+
175194
## Authors
176195

177196
* Duncan Mac-Vicar P. <[email protected]>
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
network:
2-
version: 2
3-
config:
4-
- type: physical
5-
name: ens3
6-
subnets:
7-
- type: dhcp
1+
version: 2
2+
ethernets:
3+
ens3:
4+
dhcp4: true
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## Flatcar Linux simple cluster setup
2+
3+
### Requirements
4+
5+
This setup works with the following config:
6+
```shell
7+
$ libvirtd --version
8+
libvirtd (libvirt) 5.5.0
9+
$ terraform version
10+
Terraform v0.12.6
11+
```
12+
13+
### Flatcar Linux
14+
15+
Ths example is strongly inspired by the CoreOS [example](https://github.com/dmacvicar/terraform-provider-libvirt/tree/master/examples/v0.12/coreos).
16+
17+
QEMU-agent is not used, network is configured with static IP to keep things simple.
18+
19+
```shell
20+
$ virsh net-dumpxml --network cluster-net
21+
...
22+
<ip address='192.168.122.1' netmask='255.255.255.0'>
23+
<dhcp>
24+
<range start='192.168.122.100' end='192.168.122.254'/>
25+
<host mac='52:54:00:00:00:a1' name='node-01' ip='192.168.122.101'/>
26+
<host mac='52:54:00:00:00:a2' name='node-02' ip='192.168.122.102'/>
27+
<host mac='52:54:00:00:00:a3' name='node-03' ip='192.168.122.103'/>
28+
</dhcp>
29+
</ip>
30+
...
31+
```
32+
33+
Do not forget to download Flatcar Linux image and to add it the pool of your [choice](https://docs.flatcar-linux.org/os/booting-with-libvirt/#choosing-a-channel).
34+
35+
You can specify the number of hosts by updating:
36+
```hcl
37+
variable "hosts" {
38+
default = 2
39+
}
40+
```
41+
42+
(:warning: you will need to update `units/etcd-member.conf` to add or remove or node to the initial cluster :warning:)
43+
44+
Add you SSH pub key or provide a hashed password.
45+
46+
Finally, `fw_cfg_name` is the "path" where ignition file will be mounted [doc](https://docs.flatcar-linux.org/os/booting-with-libvirt/#creating-the-domain-xml).
47+
48+
```hcl
49+
resource "libvirt_domain" "node" {
50+
...
51+
fw_cfg_name = "opt/org.flatcar-linux/config"
52+
...
53+
}
54+
```
55+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
data "ignition_config" "ignition" {
2+
users = [
3+
data.ignition_user.core.id,
4+
]
5+
6+
files = [
7+
element(data.ignition_file.hostname.*.id, count.index)
8+
]
9+
10+
networkd = [
11+
"${data.ignition_networkd_unit.network-dhcp.id}",
12+
]
13+
14+
systemd = [
15+
"${data.ignition_systemd_unit.etcd-member[count.index].id}",
16+
]
17+
18+
count = var.hosts
19+
}
20+
21+
data "ignition_file" "hostname" {
22+
filesystem = "root"
23+
path = "/etc/hostname"
24+
mode = 420
25+
26+
content {
27+
content = format(var.hostname_format, count.index + 1)
28+
}
29+
30+
count = var.hosts
31+
}
32+
33+
data "ignition_user" "core" {
34+
name = "core"
35+
36+
ssh_authorized_keys = ["ssh-rsa <your-ssh-pub-key>"]
37+
}
38+
39+
data "ignition_networkd_unit" "network-dhcp" {
40+
name = "00-wired.network"
41+
content = "${file("${path.module}/units/00-wired.network")}"
42+
}
43+
44+
data "ignition_systemd_unit" "etcd-member" {
45+
name = "etcd-member.service"
46+
enabled = true
47+
dropin {
48+
content = "${data.template_file.etcd-member[count.index].rendered}"
49+
name = "20-etcd-member.conf"
50+
}
51+
count = var.hosts
52+
}
53+
54+
resource "random_string" "token" {
55+
length = 16
56+
special = false
57+
}
58+
59+
data "template_file" "etcd-member" {
60+
template = "${file("${path.module}/units/20-etcd-member.conf")}"
61+
count = var.hosts
62+
vars = {
63+
node_name = format(var.hostname_format, count.index + 1)
64+
private_ip = format("192.168.122.1%02d", count.index + 1)
65+
cluster_token = random_string.token.result
66+
}
67+
}
68+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
provider "libvirt" {
2+
uri = "qemu:///system"
3+
}
4+
5+
variable "hosts" {
6+
default = 2
7+
}
8+
9+
variable "hostname_format" {
10+
type = string
11+
default = "node-%02d"
12+
}
13+
14+
resource "libvirt_volume" "flatcar-disk" {
15+
name = "flatcar-${format(var.hostname_format, count.index + 1)}.qcow2"
16+
count = var.hosts
17+
base_volume_name = "flatcar_production_qemu_image.img"
18+
pool = "container-linux"
19+
format = "qcow2"
20+
}
21+
22+
resource "libvirt_ignition" "ignition" {
23+
name = "${format(var.hostname_format, count.index + 1)}-ignition"
24+
pool = "container-linux"
25+
count = var.hosts
26+
content = element(data.ignition_config.ignition.*.rendered, count.index)
27+
}
28+
29+
resource "libvirt_domain" "node" {
30+
count = var.hosts
31+
name = format(var.hostname_format, count.index + 1)
32+
vcpu = 1
33+
memory = 2048
34+
35+
disk {
36+
volume_id = element(libvirt_volume.flatcar-disk.*.id, count.index)
37+
}
38+
39+
network_interface {
40+
network_name = "default"
41+
mac = "52:54:00:00:00:a${count.index + 1}"
42+
wait_for_lease = true
43+
}
44+
45+
coreos_ignition = element(libvirt_ignition.ignition.*.id, count.index)
46+
fw_cfg_name = "opt/org.flatcar-linux/config"
47+
}
48+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[Math]
2+
Name=eth0
3+
4+
[Network]
5+
DHCP=ipv4
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Service]
2+
Environment="ETCD_IMAGE_TAG=v3.2.0"
3+
Environment="ETCD_DATA_DIR=/var/lib/etcd"
4+
Environment="ETCD_OPTS=--name ${node_name} \
5+
--listen-client-urls http://0.0.0.0:2379 \
6+
--advertise-client-urls http://${private_ip}:2379 \
7+
--listen-peer-urls http://0.0.0.0:2380 \
8+
--initial-advertise-peer-urls http://${private_ip}:2380 \
9+
--initial-cluster node-01=http://192.168.122.101:2380,node-02=http://192.168.122.102:2380 \
10+
--initial-cluster-token ${cluster_token} \
11+
--initial-cluster-state new"
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
network:
2-
version: 2
3-
config:
4-
- type: physical
5-
name: ens3
6-
subnets:
7-
- type: dhcp
1+
version: 2
2+
ethernets:
3+
ens3:
4+
dhcp4: true

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ require (
2525
golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1
2626
golang.org/x/tools v0.0.0-20181219222714-6e267b5cc78e // indirect
2727
)
28+
29+
replace git.apache.org/thrift.git => github.com/apache/thrift v0.0.0-20180902110319-2566ecd5d999

go.sum

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ dmitri.shuralyov.com/app/changes v0.0.0-20180602232624-0a106ad413e3/go.mod h1:Yl
88
dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0/go.mod h1:JLBrvjyP0v+ecvNYvCpyZgu5/xkfAUhi6wJj28eUfSU=
99
dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1:a1inKt/atXimZ4Mv927x+r7UpyzRUf4emIoiiSC2TN4=
1010
dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU=
11-
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
1211
github.com/Azure/azure-sdk-for-go v21.3.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
1312
github.com/Azure/go-autorest v10.15.4+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
1413
github.com/Azure/go-ntlmssp v0.0.0-20180810175552-4a21cbd618b4/go.mod h1:chxPXzSsl7ZWRAuOIE23GDNzjWuZquvFlgA8xmpunjU=
@@ -27,6 +26,7 @@ github.com/ajeddeloh/go-json v0.0.0-20170920214419-6a2fe990e083/go.mod h1:otnto4
2726
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
2827
github.com/antchfx/xpath v0.0.0-20190129040759-c8489ed3251e/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk=
2928
github.com/antchfx/xquery v0.0.0-20180515051857-ad5b8c7a47b0/go.mod h1:LzD22aAzDP8/dyiCKFp31He4m2GPjl0AFyzDtZzUu9M=
29+
github.com/apache/thrift v0.0.0-20180902110319-2566ecd5d999/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
3030
github.com/apparentlymart/go-cidr v1.0.0 h1:lGDvXx8Lv9QHjrAVP7jyzleG4F9+FkRhJcEsDFxeb8w=
3131
github.com/apparentlymart/go-cidr v1.0.0/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc=
3232
github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3 h1:ZSTrOEhiM5J5RFxEaFvMZVEAM1KvT1YzbEOwB2EAGjA=

0 commit comments

Comments
 (0)