forked from inercia/caasp-tf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
terraform.tf
196 lines (161 loc) · 4.98 KB
/
terraform.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#
# Author(s): Flavio Castelli <flavio@suse.com>
# Alvaro Saurin <alvaro.saurin@suse.com>
#
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
#
#####################
# Cluster variables #
#####################
variable "libvirt_uri" {
default = "qemu:///system"
description = "libvirt connection url - default to localhost"
}
variable "img_pool" {
default = "default"
description = "pool to be used to store all the volumes"
}
variable "network_name" {
default = "default"
description = "default libvirt network"
}
variable "img_src" {
type = "string"
default = "http://download.suse.de/install/SUSE-CaaSP-1.0-GMC/"
description = "URL to the CaaSP image for KVM - see http://download.suse.de/ibs/SUSE:/SLE-12-SP2:/Update:/Products:/CASP10/images/ contents"
}
variable "img_local" {
type = "string"
default = "images/beta/caasp.qcow2"
description = "local copy of the image"
}
variable "img_refresh" {
default = "true"
description = "Try to get the latest image (true/false)"
}
variable "nodes_count" {
default = 3
description = "Number of non-admin nodes to be created"
}
variable "prefix" {
type = "string"
default = "caasp_beta"
description = "a prefix for resources"
}
variable "password" {
type = "string"
default = "linux"
description = "password for sshing to the VMs"
}
variable "nodes_memory" {
default = 2048
description = "RAM of the node expressed in bytes"
}
#######################
# Cluster declaration #
#######################
provider "libvirt" {
uri = "${var.libvirt_uri}"
}
resource "null_resource" "local_checkout_of_caasp_image" {
provisioner "local-exec" {
command = "./support/tf/download-image.sh --src ${var.img_src} --refresh ${var.img_refresh} --local ${var.img_local}"
}
}
# This is the CaaSP kvm image that has been created by IBS
resource "libvirt_volume" "base_img" {
name = "${basename(var.img_local)}"
source = "${var.img_local}"
pool = "${var.img_pool}"
depends_on = ["null_resource.local_checkout_of_caasp_image"]
}
##############
# Admin node #
##############
resource "libvirt_volume" "admin" {
name = "${var.prefix}_admin.qcow2"
pool = "${var.img_pool}"
base_volume_id = "${libvirt_volume.base_img.id}"
}
data "template_file" "admin_cloud_init_user_data" {
template = "${file("cloud-init/admin.cfg.tpl")}"
vars {
password = "${var.password}"
}
}
resource "libvirt_cloudinit" "admin" {
name = "${var.prefix}_admin_cloud_init.iso"
pool = "${var.img_pool}"
user_data = "${data.template_file.admin_cloud_init_user_data.rendered}"
}
resource "libvirt_domain" "admin" {
name = "${var.prefix}_admin"
memory = "${var.nodes_memory}"
cloudinit = "${libvirt_cloudinit.admin.id}"
disk {
volume_id = "${libvirt_volume.admin.id}"
}
network_interface {
network_name = "${var.network_name}"
wait_for_lease = 1
}
graphics {
type = "vnc"
listen_type = "address"
}
}
output "ip_admin" {
value = "${libvirt_domain.admin.network_interface.0.addresses.0}"
}
###########################
# Cluster non-admin nodes #
###########################
resource "libvirt_volume" "node" {
name = "${var.prefix}_node_${count.index}.qcow2"
pool = "${var.img_pool}"
base_volume_id = "${libvirt_volume.base_img.id}"
count = "${var.nodes_count}"
}
data "template_file" "node_cloud_init_user_data" {
template = "${file("cloud-init/node.cfg.tpl")}"
vars {
admin_node_ip = "${libvirt_domain.admin.network_interface.0.addresses.0}"
password = "${var.password}"
}
depends_on = ["libvirt_domain.admin"]
}
resource "libvirt_cloudinit" "node" {
name = "${var.prefix}_node_cloud_init.iso"
pool = "${var.img_pool}"
user_data = "${data.template_file.node_cloud_init_user_data.rendered}"
}
resource "libvirt_domain" "node" {
count = "${var.nodes_count}"
name = "${var.prefix}_node_${count.index}"
memory = "${var.nodes_memory}"
cloudinit = "${libvirt_cloudinit.node.id}"
depends_on = ["libvirt_domain.admin"]
disk {
volume_id = "${element(libvirt_volume.node.*.id, count.index)}"
}
network_interface {
network_name = "${var.network_name}"
wait_for_lease = 1
}
graphics {
type = "vnc"
listen_type = "address"
}
}
output "nodes" {
value = ["${libvirt_domain.node.*.network_interface.0.addresses.0}"]
}