2015-09-23 23:38:31 +00:00
|
|
|
variable "count" {}
|
|
|
|
variable "image" {}
|
|
|
|
variable "region" {}
|
2015-09-24 18:44:51 +00:00
|
|
|
variable "size" { default = "1gb" }
|
2015-09-23 21:16:36 +00:00
|
|
|
variable "servers" {}
|
2015-09-23 23:38:31 +00:00
|
|
|
variable "ssh_keys" {}
|
2015-09-23 21:16:36 +00:00
|
|
|
|
|
|
|
resource "template_file" "client_config" {
|
2015-09-24 02:02:04 +00:00
|
|
|
filename = "${path.module}/client.hcl.tpl"
|
2015-09-23 21:16:36 +00:00
|
|
|
vars {
|
|
|
|
datacenter = "${var.region}"
|
|
|
|
servers = "${split(",", var.servers)}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "digitalocean_droplet" "client" {
|
2015-09-23 23:38:31 +00:00
|
|
|
image = "${var.image}"
|
2015-09-24 18:08:08 +00:00
|
|
|
name = "nomad-client-${var.region}-${count.index}"
|
2015-09-23 23:38:31 +00:00
|
|
|
count = "${var.count}"
|
|
|
|
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/client.hcl <<EOF
|
2015-09-23 23:51:51 +00:00
|
|
|
${template_file.client_config.rendered}
|
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
|
|
|
}
|
|
|
|
}
|