-
Notifications
You must be signed in to change notification settings - Fork 0
/
mk.tf
206 lines (175 loc) · 5.44 KB
/
mk.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
197
198
199
200
201
202
203
204
205
206
# Configure the Packet Provider
provider "packet" {
auth_token = "${var.packet_api_key}"
}
# Create a new SSH key
resource "packet_ssh_key" "mk_key" {
name = "mk_key"
public_key = "${file("${var.ssh_private_key}.pub")}"
}
# Create mk project
resource "packet_project" "mk" {
name = "mk_lab"
}
# Create Salt master cfg01
resource "packet_device" "cfg01" {
hostname = "cfg01.${var.cluster_domain}"
plan = "${var.packet_machine_type}"
facility = "${var.packet_location}"
operating_system = "ubuntu_16_04_image"
billing_cycle = "hourly"
project_id = "${packet_project.mk.id}"
connection {
type = "ssh"
user = "root"
port = 22
timeout = "1200"
private_key = "${file("${var.ssh_private_key}")}"
}
provisioner "file" {
source = "templates/weave.sh"
destination = "/root/weave.sh"
}
# Set up additional eth interface using weave
provisioner "remote-exec" {
inline = [
"export ubuntu_release='xenial'",
"export private_ip_address=''",
"/bin/bash weave.sh"
]
}
}
resource "null_resource" "cfg01_master_provision" {
depends_on = ["packet_device.cfg01"]
connection {
type = "ssh"
host = "${packet_device.cfg01.network.0.address}"
user = "root"
port = 22
timeout = "1200"
private_key = "${file("${var.ssh_private_key}")}"
}
provisioner "file" {
source = "templates/master.sh"
destination = "/root/master.sh"
}
# set up salt master
provisioner "remote-exec" {
inline = [
"export node_name='cfg01.${var.cluster_domain}'",
"export reclass_address='https://github.com/tlichten/mk-lab-salt-model'",
"export reclass_branch='dash'",
"export private_ip='${packet_device.cfg01.network.2.address}'",
"/bin/bash master.sh"
]
}
provisioner "file" {
source = "templates/setipaddress.sh"
destination = "/root/setipaddress.sh"
}
# Set up ip address for interface weave
provisioner "remote-exec" {
inline = [
"/bin/bash setipaddress.sh"
]
}
}
variable "nodes" {
default = {
"0" = "ctl01"
"1" = "ctl02"
"2" = "ctl03"
"3" = "cmp01"
"4" = "mon01"
"5" = "prx01"
}
}
resource "packet_device" "node" {
depends_on = ["null_resource.cfg01_master_provision"]
count = "6"
hostname = "${lookup(var.nodes, count.index)}.${var.cluster_domain}"
plan = "${var.packet_machine_type}"
facility = "${var.packet_location}"
operating_system = "ubuntu_14_04_image"
billing_cycle = "hourly"
project_id = "${packet_project.mk.id}"
connection {
type = "ssh"
user = "root"
port = 22
timeout = "1200"
private_key = "${file("${var.ssh_private_key}")}"
}
provisioner "file" {
source = "templates/weave.sh"
destination = "/root/weave.sh"
}
# Set up additional eth interface using weave
provisioner "remote-exec" {
inline = [
"export ubuntu_release='trusty'",
"export private_ip_address='${packet_device.cfg01.network.2.address}'",
"/bin/bash weave.sh"
]
}
provisioner "file" {
source = "templates/slave_workaround.sh"
destination = "/root/slave_workaround.sh"
}
# some additional packages are needed to satisfy installation
provisioner "remote-exec" {
inline = [
"/bin/bash slave_workaround.sh"
]
}
provisioner "file" {
source = "templates/slave.sh"
destination = "/root/slave.sh"
}
# set up salt minions/slaves
provisioner "remote-exec" {
inline = [
"export node_name='${lookup(var.nodes, count.index)}.${var.cluster_domain}'",
"export config_host='${packet_device.cfg01.network.2.address}'",
"/bin/bash slave.sh"
]
}
provisioner "file" {
source = "templates/setipaddress.sh"
destination = "/root/setipaddress.sh"
}
# Set up ip address for interface weave
provisioner "remote-exec" {
inline = [
"/bin/bash setipaddress.sh"
]
}
}
# run mk22 bootstrap: controller services, compute services, contrail, network
# and launch demo vm with network and floating ip
resource "null_resource" "bootstrap" {
depends_on = ["packet_device.node"]
connection {
type = "ssh"
host = "${packet_device.cfg01.network.0.address}"
user = "root"
port = 22
timeout = "1200"
private_key = "${file("${var.ssh_private_key}")}"
}
provisioner "remote-exec" {
inline = [
"cd /srv/salt/reclass/scripts/ && ./bootstrap_all.sh"
]
}
}
output "salt_master" {
value = "${packet_device.cfg01.network.0.address}"
}
output "steps" {
value = [
"ssh root@${packet_device.cfg01.network.0.address}",
"salt 'ctl01*' cmd.run '. /root/keystonerc; nova list'",
"ssh cirros@<floating-ip> #password cubswin:)"
]
}