open-nomad/demo/digitalocean/terraform/server/main.tf

55 lines
1.2 KiB
Terraform
Raw Normal View History

variable "image" {}
2015-09-23 21:16:36 +00:00
variable "region" {}
variable "size" { default = "8gb" }
variable "ssh_keys" {}
variable "statsite" {}
2015-09-23 21:16:36 +00:00
resource "digitalocean_droplet" "server" {
image = "${var.image}"
name = "nomad-server-${var.region}-${count.index}"
count = 3
size = "${var.size}"
region = "${var.region}"
ssh_keys = ["${split(",", var.ssh_keys)}"]
2015-09-23 21:16:36 +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"
}
telemetry {
statsite_address = "${var.statsite}"
disable_hostname = true
}
2015-09-24 01:04:41 +00:00
EOF
CMD
2015-09-23 21:16:36 +00:00
}
provisioner "remote-exec" {
inline = "sudo start nomad || sudo restart nomad"
2015-09-23 21:16:36 +00:00
}
}
resource "null_resource" "server_join" {
provisioner "local-exec" {
2015-09-24 01:04:41 +00:00
command = <<CMD
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: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
}