Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ resource "digitalocean_ssh_key" "default" {

resource "digitalocean_droplet" "nomad_server" {
count = var.nomad_servers_count
image = data.digitalocean_images.cluster_server.images[0].id
image = var.snapshot
# Consul members name must be unique
name = "nomad-cluster-server-${count.index}"
region = var.do_region
Expand All @@ -78,7 +78,7 @@ resource "digitalocean_droplet" "nomad_server" {

resource "digitalocean_droplet" "nomad_client" {
count = var.nomad_clients_count
image = data.digitalocean_images.cluster_server.images[0].id
image = var.snapshot
# Consul members name must be unique
name = "nomad-cluster-general-client-${count.index}"
region = var.do_region
Expand All @@ -93,7 +93,7 @@ resource "digitalocean_droplet" "nomad_client" {
}

resource "digitalocean_droplet" "ingress_client" {
image = data.digitalocean_images.cluster_server.images[0].id
image = var.snapshot
# Consul members name must be unique
name = "nomad-cluster-ingress"
region = var.do_region
Expand Down
5 changes: 5 additions & 0 deletions cluster/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ output "server_droplet_ips" {
value = join(",", digitalocean_droplet.nomad_server[*].ipv4_address)
}

output "nomad_address" {
// This makes the provider definition a bit simpiler
value = "http://${digitalocean_droplet.nomad_server[0].ipv4_address}:4646"
}

output "ingress_droplet_ip" {
value = digitalocean_droplet.ingress_client.ipv4_address
}
Expand Down
4 changes: 4 additions & 0 deletions cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ variable "do_token" {
type = string
}

variable "snapshot" {
type = string
}

variable "do_region" {
type = string
default = "lon1"
Expand Down
48 changes: 48 additions & 0 deletions image/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.8.0"
}
}
}


locals {
build_image = var.image == ""
image = local.build_image ? data.digitalocean_image.built[0] : data.digitalocean_image.existing[0]
}

resource "random_pet" "name" {
count = local.build_image ? 1 : 0
}

resource "null_resource" "packer_build" {
count = local.build_image ? 1 : 0

provisioner "local-exec" {
command = <<EOF
cd ${path.module}/packer && \
packer build -force \
-var 'name=hashi-${random_pet.name[0].id}' \
-var 'region=${var.region}' \
-var 'token=${var.do_token}' \
do-packer.pkr.hcl
EOF
}
}

data "digitalocean_image" "built" {
depends_on = [null_resource.packer_build]
count = local.build_image ? 1 : 0
name = "hashi-${random_pet.name[0].id}"
}

data "digitalocean_image" "existing" {
count = local.build_image ? 0 : 1
name = var.image
}

output "snapshot_id" {
value = local.image.id
}
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions image/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
variable "do_token" {}

variable "region" {
type = string
}

variable "image" {
type = string
default = ""
}
53 changes: 53 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.8.0"
}
}
}

provider "digitalocean" {
token = var.do_token
}

provider "nomad" {
address = module.cluster.nomad_address
}

# Pre-flight check.
resource "null_resource" "preflight_check" {
provisioner "local-exec" {
command = <<EOF
curl --version && \
packer --version && \
nomad --version
EOF
}
}

module "image" {
depends_on = [null_resource.preflight_check]
}


module "cluster" {
depends_on = [null_resource.preflight_check]
source = "./cluster"
do_token = var.do_token
snapshot_id = module.image.snapshot_id
ssh_key = var.ssh_key
region = var.region
ip_range = var.ip_range
}


module "jobs" {
depends_on = [null_resource.preflight_check]
}

module "vault" {
depends_on = [null_resource.preflight_check]
}


8 changes: 8 additions & 0 deletions shared/config/nomad.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ plugin "raw_exec" {
config {
enabled = true
}
}

telemetry {
collection_interval = "1s"
disable_hostname = true
prometheus_metrics = true
publish_allocation_metrics = true
publish_node_metrics = true
}
8 changes: 8 additions & 0 deletions shared/config/nomad_client.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ vault {
enabled = true
address = "http://active.vault.service.consul:8200"
}

telemetry {
collection_interval = "1s"
disable_hostname = true
prometheus_metrics = true
publish_allocation_metrics = true
publish_node_metrics = true
}