Skip to content

Commit

Permalink
Create replica on green cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
lens0021 committed Oct 6, 2024
1 parent a6bc379 commit dcf9622
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
17 changes: 8 additions & 9 deletions jobs/mysql.nomad
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
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" {
datacenters = ["dc1"]

group "mysql" {
dynamic "volume" {
for_each = local.main ? [{}] : []
for_each = local.blue ? [{}] : []
labels = ["mysql"]

content {
Expand All @@ -29,7 +28,7 @@ job "mysql" {
driver = "docker"

dynamic "volume_mount" {
for_each = local.main ? [{}] : []
for_each = local.blue ? [{}] : []

content {
volume = "mysql"
Expand Down Expand Up @@ -64,7 +63,7 @@ job "mysql" {
network {
mode = "bridge"
dynamic "port" {
for_each = local.main ? [{}] : []
for_each = local.blue ? [{}] : []
labels = ["network"]

content {
Expand All @@ -75,7 +74,7 @@ job "mysql" {
}

dynamic "service" {
for_each = var.test ? [{}] : []
for_each = var.green ? [{}] : []
content {
name = "mysql"
port = "3306"
Expand Down
16 changes: 16 additions & 0 deletions terraform/mediawiki.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions terraform/volumes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dcf9622

Please sign in to comment.