diff --git a/jobs/mysql.nomad b/jobs/mysql.nomad index 63cb2f5..d620e34 100644 --- a/jobs/mysql.nomad +++ b/jobs/mysql.nomad @@ -1,11 +1,10 @@ -variable "test" { - type = bool - description = "Uses jobs for the test server. Without CSI" - default = false +variable "green" { + type = bool + default = false } locals { - main = !var.test + blue = !var.green } job "mysql" { @@ -13,7 +12,7 @@ job "mysql" { group "mysql" { dynamic "volume" { - for_each = local.main ? [{}] : [] + for_each = local.blue ? [{}] : [] labels = ["mysql"] content { @@ -29,7 +28,7 @@ job "mysql" { driver = "docker" dynamic "volume_mount" { - for_each = local.main ? [{}] : [] + for_each = local.blue ? [{}] : [] content { volume = "mysql" @@ -64,7 +63,7 @@ job "mysql" { network { mode = "bridge" dynamic "port" { - for_each = local.main ? [{}] : [] + for_each = local.blue ? [{}] : [] labels = ["network"] content { @@ -75,7 +74,7 @@ job "mysql" { } dynamic "service" { - for_each = var.test ? [{}] : [] + for_each = var.green ? [{}] : [] content { name = "mysql" port = "3306" diff --git a/terraform/mediawiki.tf b/terraform/mediawiki.tf index b935b8e..4fcd150 100644 --- a/terraform/mediawiki.tf +++ b/terraform/mediawiki.tf @@ -12,6 +12,22 @@ resource "nomad_job" "mysql" { } } +resource "nomad_job" "mysql_green" { + depends_on = [ + nomad_csi_volume_registration.mysql_green, + ] + + jobspec = file("../jobs/mysql.nomad") + detach = false + + hcl2 { + allow_fs = true + vars = { + green = true + } + } +} + resource "nomad_job" "memcached" { jobspec = file("../jobs/memcached.nomad") detach = false diff --git a/terraform/volumes.tf b/terraform/volumes.tf index c56a338..f589113 100644 --- a/terraform/volumes.tf +++ b/terraform/volumes.tf @@ -54,6 +54,18 @@ resource "nomad_csi_volume_registration" "mysql" { } } +resource "nomad_csi_volume_registration" "mysql_green" { + plugin_id = "aws-ebs0" + volume_id = "mysql_green" + name = "mysql_green" + external_id = data.terraform_remote_state.aws.outputs.ebs_mysql_green_id + + capability { + access_mode = "single-node-writer" + attachment_mode = "file-system" + } +} + import { id = "caddycerts@default" to = nomad_csi_volume_registration.caddycerts