Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create replica on green cluster #302

Merged
merged 1 commit into from
Oct 6, 2024
Merged
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
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