github.com/mattyr/nomad@v0.3.3-0.20160919021406-3485a065154a/demo/digitalocean/terraform/server/main.tf (about)

     1  variable "image" {}
     2  variable "region" {}
     3  variable "size" { default = "8gb" }
     4  variable "ssh_keys" {}
     5  variable "statsite" {}
     6  
     7  resource "digitalocean_droplet" "server" {
     8    image    = "${var.image}"
     9    name     = "nomad-server-${var.region}-${count.index}"
    10    count    = 3
    11    size     = "${var.size}"
    12    region   = "${var.region}"
    13    ssh_keys = ["${split(",", var.ssh_keys)}"]
    14  
    15    provisioner "remote-exec" {
    16      inline = <<CMD
    17  cat > /usr/local/etc/nomad/server.hcl <<EOF
    18  datacenter = "${var.region}"
    19  server {
    20      enabled = true
    21      bootstrap_expect = 3
    22  }
    23  advertise {
    24      rpc = "${self.ipv4_address}:4647"
    25      serf = "${self.ipv4_address}:4648"
    26  }
    27  telemetry {
    28      statsite_address = "${var.statsite}"
    29      disable_hostname = true
    30  }
    31  EOF
    32  CMD
    33    }
    34  
    35    provisioner "remote-exec" {
    36      inline = "sudo start nomad || sudo restart nomad"
    37    }
    38  }
    39  
    40  resource "null_resource" "server_join" {
    41    provisioner "local-exec" {
    42      command = <<CMD
    43  join() {
    44    curl -X PUT ${digitalocean_droplet.server.0.ipv4_address}:4646/v1/agent/join?address=$1
    45  }
    46  join ${digitalocean_droplet.server.1.ipv4_address}
    47  join ${digitalocean_droplet.server.2.ipv4_address}
    48  CMD
    49    }
    50  }
    51  
    52  output "addrs" {
    53    value = "${join(",", digitalocean_droplet.server.*.ipv4_address)}"
    54  }