From d5078b24da151a9ca10f4b86306680ef04a9fb7a Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Thu, 24 Aug 2023 12:36:47 -0700 Subject: [PATCH] Refactor use of wesher to be behind a variable toggle Occasionally I run into issues with Wesher. This makes it easier to disable use of Wesher by setting TF_VAR_use_wesher to false. --- backups.tf | 2 ++ backups/backup.nomad | 2 ++ backups/backups.tf | 2 ++ backups/vars.tf | 5 +++++ core.tf | 1 + core/authelia.tf | 1 + core/blocky/blocky.nomad | 16 +++++++------- core/blocky/blocky.tf | 12 ++++------- core/blocky/vars.tf | 11 ++++++++++ core/lldap.nomad | 28 ++++++++++++++----------- core/loki.tf | 11 ++++++---- core/main.tf | 10 +++++++-- core/metrics/exporters.nomad | 10 +++++---- core/metrics/grafana.nomad | 2 ++ core/metrics/metrics.tf | 9 ++++++-- core/metrics/prometheus.nomad | 12 +++++++---- core/metrics/vars.tf | 5 +++++ core/vars.tf | 6 ++++++ services.tf | 2 ++ services/adminer.tf | 1 + services/bazarr.tf | 1 + services/ip-dvr.nomad | 6 ++++++ services/lidarr.tf | 1 + services/main.tf | 8 +++---- services/media-library.tf | 2 ++ services/minitor.tf | 1 + services/photoprism.tf | 1 + services/service/main.tf | 1 + services/service/service_template.nomad | 2 ++ services/service/vars.tf | 6 ++++++ services/vars.tf | 5 +++++ services/whoami.nomad | 4 +++- services/whoami.tf | 4 +++- vars.tf | 6 ++++++ 34 files changed, 146 insertions(+), 50 deletions(-) create mode 100644 backups/vars.tf create mode 100644 core/blocky/vars.tf create mode 100644 core/metrics/vars.tf create mode 100644 services/vars.tf diff --git a/backups.tf b/backups.tf index 16883e2..ee57db1 100644 --- a/backups.tf +++ b/backups.tf @@ -1,3 +1,5 @@ module "backups" { source = "./backups" + + use_wesher = var.use_wesher } diff --git a/backups/backup.nomad b/backups/backup.nomad index eb8f7c5..8a28215 100644 --- a/backups/backup.nomad +++ b/backups/backup.nomad @@ -31,7 +31,9 @@ job "backup%{ if batch_node != null }-oneoff-${batch_node}%{ endif }" { mode = "bridge" port "metrics" { + %{~ if use_wesher ~} host_network = "wesher" + %{~ endif ~} to = 8080 } } diff --git a/backups/backups.tf b/backups/backups.tf index d3c4d21..8a2b921 100644 --- a/backups/backups.tf +++ b/backups/backups.tf @@ -6,6 +6,7 @@ resource "nomad_job" "backup" { jobspec = templatefile("${path.module}/backup.nomad", { module_path = path.module, batch_node = null, + use_wesher = var.use_wesher }) } @@ -24,5 +25,6 @@ resource "nomad_job" "backup-oneoff" { jobspec = templatefile("${path.module}/backup.nomad", { module_path = path.module, batch_node = each.key, + use_wesher = var.use_wesher }) } diff --git a/backups/vars.tf b/backups/vars.tf new file mode 100644 index 0000000..aa5858a --- /dev/null +++ b/backups/vars.tf @@ -0,0 +1,5 @@ +variable "use_wesher" { + type = bool + description = "Indicates whether or not services should expose themselves on the wesher network" + default = true +} diff --git a/core.tf b/core.tf index 3d47af9..2374f5d 100644 --- a/core.tf +++ b/core.tf @@ -6,6 +6,7 @@ module "core" { source = "./core" base_hostname = var.base_hostname + use_wesher = var.use_wesher # Metrics and Blocky depend on databases depends_on = [module.databases] diff --git a/core/authelia.tf b/core/authelia.tf index bbcd56c..5bda631 100644 --- a/core/authelia.tf +++ b/core/authelia.tf @@ -9,6 +9,7 @@ module "authelia" { ingress = true service_port = 9999 service_port_static = true + use_wesher = var.use_wesher # metrics_port = 9959 env = { diff --git a/core/blocky/blocky.nomad b/core/blocky/blocky.nomad index 3fda8f6..aad22ef 100644 --- a/core/blocky/blocky.nomad +++ b/core/blocky/blocky.nomad @@ -24,7 +24,9 @@ job "blocky" { } port "api" { + %{~ if use_wesher ~} host_network = "wesher" + %{~ endif ~} to = "4000" } @@ -66,7 +68,7 @@ job "blocky" { config { image = "ghcr.io/0xerr0r/blocky" - args = ["-c", "${NOMAD_TASK_DIR}/config.yml"] + args = ["-c", "$${NOMAD_TASK_DIR}/config.yml"] ports = ["dns", "api"] } @@ -78,7 +80,7 @@ job "blocky" { template { data = var.config_data - destination = "${NOMAD_TASK_DIR}/config.yml" + destination = "$${NOMAD_TASK_DIR}/config.yml" splay = "1m" wait { @@ -95,7 +97,7 @@ job "blocky" { {{- end }} {{- end }} EOF - destination = "${NOMAD_TASK_DIR}/nomad.hosts" + destination = "$${NOMAD_TASK_DIR}/nomad.hosts" change_mode = "noop" wait { @@ -116,7 +118,7 @@ job "blocky" { config { image = "alpine:3.17" ports = ["tls"] - args = ["/bin/sh", "${NOMAD_TASK_DIR}/start.sh"] + args = ["/bin/sh", "$${NOMAD_TASK_DIR}/start.sh"] } resources { @@ -130,7 +132,7 @@ set -e apk add stunnel exec stunnel {{ env "NOMAD_TASK_DIR" }}/stunnel.conf EOF - destination = "${NOMAD_TASK_DIR}/start.sh" + destination = "$${NOMAD_TASK_DIR}/start.sh" } template { @@ -155,7 +157,7 @@ connect = {{ .Address }}:{{ .Port }} {{- end }} PSKsecrets = {{ env "NOMAD_SECRETS_DIR" }}/stunnel_psk.txt EOF - destination = "${NOMAD_TASK_DIR}/stunnel.conf" + destination = "$${NOMAD_TASK_DIR}/stunnel.conf" } template { @@ -169,7 +171,7 @@ EOF data = <