-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Scott Winkler
authored and
Scott Winkler
committed
Feb 7, 2021
0 parents
commit bde9e3e
Showing
9 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "browserquest_address" { | ||
value = var.fabio_lb | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
variable "fabio_db" { | ||
type = string | ||
} | ||
|
||
variable "fabio_lb" { | ||
type = string | ||
} |