2015-09-23 23:38:31 +00:00
|
|
|
variable "image" {}
|
2015-09-23 21:16:36 +00:00
|
|
|
variable "region" {}
|
2015-09-27 21:07:39 +00:00
|
|
|
variable "size" { default = "8gb" }
|
2015-09-23 23:38:31 +00:00
|
|
|
variable "ssh_keys" {}
|
2015-09-24 19:26:17 +00:00
|
|
|
variable "statsite" {}
|
2015-09-23 21:16:36 +00:00
|
|
|
|
|
|
|
resource "digitalocean_droplet" "server" {
|
2015-09-23 23:38:31 +00:00
|
|
|
image = "${var.image}"
|
2015-09-24 18:08:08 +00:00
|
|
|
name = "nomad-server-${var.region}-${count.index}"
|
2015-09-24 17:50:41 +00:00
|
|
|
count = 3
|
2015-09-23 23:38:31 +00:00
|
|
|
size = "${var.size}"
|
|
|
|
region = "${var.region}"
|
|
|
|
ssh_keys = ["${split(",", var.ssh_keys)}"]
|
2015-09-23 21:16:36 +00:00
|
|
|
|
2015-09-23 23:51:51 +00:00
|
|
|
provisioner "remote-exec" {
|
2015-09-24 01:04:41 +00:00
|
|
|
inline = <<CMD
|
|
|
|
cat > /usr/local/etc/nomad/server.hcl <<EOF
|
|
|
|
datacenter = "${var.region}"
|
|
|
|
server {
|
|
|
|
enabled = true
|
|
|
|
bootstrap_expect = 3
|
|
|
|
}
|
|
|
|
advertise {
|
|
|
|
rpc = "${self.ipv4_address}:4647"
|
|
|
|
serf = "${self.ipv4_address}:4648"
|
|
|
|
}
|
2015-09-24 19:26:17 +00:00
|
|
|
telemetry {
|
|
|
|
statsite_address = "${var.statsite}"
|
2015-09-26 05:44:34 +00:00
|
|
|
disable_hostname = true
|
2015-09-24 19:26:17 +00:00
|
|
|
}
|
2015-09-24 01:04:41 +00:00
|
|
|
EOF
|
|
|
|
CMD
|
2015-09-23 21:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "remote-exec" {
|
2015-09-24 02:02:04 +00:00
|
|
|
inline = "sudo start nomad || sudo restart nomad"
|
2015-09-23 21:16:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-23 21:47:46 +00:00
|
|
|
resource "null_resource" "server_join" {
|
|
|
|
provisioner "local-exec" {
|
2015-09-24 01:04:41 +00:00
|
|
|
command = <<CMD
|
2015-09-23 21:47:46 +00:00
|
|
|
join() {
|
|
|
|
curl -X PUT ${digitalocean_droplet.server.0.ipv4_address}:4646/v1/agent/join?address=$1
|
|
|
|
}
|
|
|
|
join ${digitalocean_droplet.server.1.ipv4_address}
|
|
|
|
join ${digitalocean_droplet.server.2.ipv4_address}
|
2015-09-24 01:04:41 +00:00
|
|
|
CMD
|
2015-09-23 21:47:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-23 21:16:36 +00:00
|
|
|
output "addrs" {
|
2015-09-23 21:47:18 +00:00
|
|
|
value = "${join(",", digitalocean_droplet.server.*.ipv4_address)}"
|
2015-09-23 21:16:36 +00:00
|
|
|
}
|