Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Winkler authored and Scott Winkler committed Feb 7, 2021
0 parents commit bde9e3e
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log
terraform
.DS_Store
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# terraform-nomad-mmorpg

Deploys BrowserQuest, an MMORPG on Azure + AWS using federated Nomad clusters. Mean for use with "Terraform in Action", chapter 8
29 changes: 29 additions & 0 deletions jobs/aws_fabio.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
job "fabio" {
datacenters = ["aws"]
region = "${region}"
type = "system"
group "fabio" {
task "fabio" {
driver = "docker"
config {
image = "fabiolb/fabio"
network_mode = "host"
}

resources {
cpu = 200
memory = 128
network {
mbits = 20

port "lb" {
static = 9999
}
port "ui" {
static = 9998
}
}
}
}
}
}
39 changes: 39 additions & 0 deletions jobs/azure_fabio.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
job "fabio" {
datacenters = ["azure"]
region = "${region}"
type = "system"
group "fabio" {
volume "vol" {
type = "host"
read_only = false
source = "fabio"
}
task "fabio" {
driver = "docker"
config {
image = "fabiolb/fabio"
network_mode = "host"
}

volume_mount {
volume = "vol"
destination = "/etc/fabio/fabio.properties"
read_only = false
}

resources {
cpu = 200
memory = 128
network {
mbits = 20
port "db" {
static = 27017
}
port "ui" {
static = 9998
}
}
}
}
}
}
44 changes: 44 additions & 0 deletions jobs/browserquest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
job "browserquest" {
datacenters = ["aws"]
region = "${region}"

group "browserquest" {
task "server" {
driver = "docker"

config {
image = "swinkler/browserquest"
command = "/bin/bash"
args = [
"-c",
"node server.js --mongoServer ${address}"
]

port_map {
http = "8080"
}

}

resources {
network {
mbits = 10
port "http" {}
}
}

service {
name = "browserquest-aws"
tags = ["urlprefix-/"]
port = "http"
check {
name = "alive"
type = "http"
path = "/"
interval = "10s"
timeout = "2s"
}
}
}
}
}
40 changes: 40 additions & 0 deletions jobs/mongo.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
job "mongo" {
datacenters = ["azure"]
region = "${region}"
type = "service"
group "mongo" {
ephemeral_disk {
size = 300
}

task "server" {
driver = "docker"

config {
image = "mongo:3.4.4"
port_map = {
mongo = 27017
}
}

resources {
network {
mbits = 10
port "mongo" {
}
}
}

service {
name = "mongodb-azure"
tags = ["urlprefix-:27017 proto=tcp"]
port = "mongo"
check {
type = "tcp"
interval = "10s"
timeout = "2s"
}
}
}
}
}
36 changes: 36 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
provider "nomad" {
alias = "aws"
}

provider "nomad" {
alias = "azure"
}

data "nomad_regions" "current" {
provider = nomad.aws
}

locals {
aws_region = sort(data.nomad_regions.current.regions)[1]
azure_region = sort(data.nomad_regions.current.regions)[0]
}

resource "nomad_job" "aws_fabio" {
jobspec = templatefile("${path.module}/jobs/aws_fabio.hcl",{region = local.aws_region})
provider = nomad.aws
}

resource "nomad_job" "azure_fabio" {
jobspec = templatefile("${path.module}/jobs/azure_fabio.hcl",{region = local.azure_region})
provider = nomad.azure
}

resource "nomad_job" "azure_mongo" {
jobspec = templatefile("${path.module}/jobs/mongo.hcl",{region = local.azure_region})
provider = nomad.azure
}

resource "nomad_job" "aws_browserquest" {
jobspec = templatefile("${path.module}/jobs/browserquest.hcl",{region=local.aws_region,address=replace(var.fabio_db,"tcp://","")})
provider = nomad.aws
}
3 changes: 3 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "browserquest_address" {
value = var.fabio_lb
}
7 changes: 7 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
variable "fabio_db" {
type = string
}

variable "fabio_lb" {
type = string
}

0 comments on commit bde9e3e

Please sign in to comment.