-
Notifications
You must be signed in to change notification settings - Fork 1
/
nomad_server.tf
159 lines (136 loc) · 4.91 KB
/
nomad_server.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
// 3 nomad server instances
resource "google_compute_instance" "nomad-server" {
depends_on = ["google_compute_instance.consul-server"]
count = "${var.counts["nomad-server"]}"
name = "nomad-server-${count.index}"
machine_type = "${var.machineTypes["nomad-server"]}"
zone = "${var.region}-a"
tags = ["workshirt-cluster-dc1", "nomad-server", "consul-client", "http-server"]
metadata {
sshKeys = "${var.userName}:${file("~/.ssh/id_rsa.pub")}"
}
boot_disk {
initialize_params {
image = "${var.imageSpec}"
}
}
service_account {
email = "${var.serviceAccount["email"]}"
scopes = "${list(var.serviceAccount["scopes"])}"
}
network_interface {
network = "default"
access_config {
// Include this section to give the VM an external ip address
}
}
provisioner "remote-exec" {
connection {
type = "ssh"
user = "${var.userName}"
private_key = "${file("/Users/${var.userName}/.ssh/id_rsa")}"
}
inline = [
"sudo apt-get -y update",
"sudo apt-get -y install unzip",
"mkdir /home/${var.userName}/nomad.d",
"mkdir /home/${var.userName}/opt",
"mkdir /home/${var.userName}/opt/nomad",
"mkdir /home/${var.userName}/consul.d",
"mkdir /home/${var.userName}/consul.d/data",
]
}
provisioner "file" {
connection {
type = "ssh"
user = "${var.userName}"
private_key = "${file("/Users/${var.userName}/.ssh/id_rsa")}"
}
content = <<HCL
datacenter = "dc1"
data_dir = "/home/${var.userName}/opt/nomad"
server {
enabled = true
bootstrap_expect = ${var.counts["nomad-server"]}
}
HCL
destination = "/home/${var.userName}/nomad.d/server.hcl"
}
provisioner "file" {
connection {
type = "ssh"
user = "${var.userName}"
private_key = "${file("/Users/${var.userName}/.ssh/id_rsa")}"
}
source = "${var.localPath}/zips/consul_${var.consulVersion}_linux_amd64.zip"
destination = "/home/${var.userName}/consul_${var.consulVersion}_linux_amd64.zip"
}
provisioner "file" {
connection {
type = "ssh"
user = "${var.userName}"
private_key = "${file("/Users/${var.userName}/.ssh/id_rsa")}"
}
source = "${var.localPath}/zips/nomad-enterprise_0.8.6+ent_linux_amd64.zip"
destination = "/home/${var.userName}/nomad-enterprise_0.8.6+ent_linux_amd64.zip"
}
provisioner "file" {
connection {
type = "ssh"
user = "${var.userName}"
private_key = "${file("/Users/${var.userName}/.ssh/id_rsa")}"
}
content = <<JSON
{
${jsonencode("server")}: false,
${jsonencode("node_name")}: ${jsonencode("nomad-server-${count.index}")},
${jsonencode("datacenter")}: ${jsonencode("dc1")},
${jsonencode("data_dir")}: ${jsonencode("/home/${var.userName}/consul.d/data")},
${jsonencode("bind_addr")}: ${jsonencode("0.0.0.0")},
${jsonencode("client_addr")}: ${jsonencode("0.0.0.0")},
${jsonencode("advertise_addr")}: ${jsonencode("${self.network_interface.0.access_config.0.nat_ip}")},
${jsonencode("retry_join")}: ${jsonencode("${list("provider=gce project_name=${var.userName}-test tag_value=workshirt-cluster-dc1")}")},
${jsonencode("log_level")}: ${jsonencode("DEBUG")},
${jsonencode("enable_syslog")}: true,
${jsonencode("acl_enforce_version_8")}: false
}
JSON
destination = "/home/${var.userName}/consul.d/client.json"
}
provisioner "file" {
connection {
type = "ssh"
user = "${var.userName}"
private_key = "${file("/Users/${var.userName}/.ssh/id_rsa")}"
}
content = "${data.template_file.consul-systemd-client.rendered}"
destination = "/home/${var.userName}/consul-client.service"
}
provisioner "file" {
connection {
type = "ssh"
user = "${var.userName}"
private_key = "${file("/Users/${var.userName}/.ssh/id_rsa")}"
}
content = "${data.template_file.nomad-systemd-server.rendered}"
destination = "/home/${var.userName}/nomad.service"
}
provisioner "remote-exec" {
connection {
type = "ssh"
user = "${var.userName}"
private_key = "${file("/Users/${var.userName}/.ssh/id_rsa")}"
}
inline = [
"unzip /home/${var.userName}/nomad-enterprise_0.8.6+ent_linux_amd64.zip",
"unzip /home/${var.userName}/consul_${var.consulVersion}_linux_amd64.zip",
"sudo mv /home/${var.userName}/consul /bin/",
"sudo mv /home/${var.userName}/nomad /bin/",
"rm /home/${var.userName}/nomad-enterprise_0.8.6+ent_linux_amd64.zip",
"rm /home/${var.userName}/consul_${var.consulVersion}_linux_amd64.zip",
"sudo mv /home/${var.userName}/*.service /etc/systemd/system/",
"sudo systemctl start consul-client",
"sudo systemctl start nomad",
]
}
}