2023-03-24 23:32:37 +00:00
|
|
|
resource "nomad_job" "backup" {
|
2023-07-07 22:50:58 +00:00
|
|
|
hcl2 {
|
|
|
|
enabled = true
|
|
|
|
}
|
|
|
|
|
2022-07-28 00:02:29 +00:00
|
|
|
jobspec = templatefile("${path.module}/backup.nomad", {
|
2022-11-02 19:32:27 +00:00
|
|
|
module_path = path.module,
|
2022-07-28 00:02:29 +00:00
|
|
|
batch_node = null,
|
2023-08-24 19:36:47 +00:00
|
|
|
use_wesher = var.use_wesher
|
2022-07-28 00:02:29 +00:00
|
|
|
})
|
2022-05-18 21:23:28 +00:00
|
|
|
}
|
|
|
|
|
2023-03-24 23:32:37 +00:00
|
|
|
resource "nomad_job" "backup-oneoff" {
|
2022-10-27 21:28:34 +00:00
|
|
|
# TODO: Get list of nomad hosts dynamically
|
2023-08-03 16:53:03 +00:00
|
|
|
for_each = toset(["n1", "n2", "pi4"])
|
2022-10-31 22:21:25 +00:00
|
|
|
# for_each = toset([
|
|
|
|
# for node in data.consul_service.nomad.service :
|
|
|
|
# node.node_name
|
|
|
|
# ])
|
2023-07-07 22:50:58 +00:00
|
|
|
|
|
|
|
hcl2 {
|
|
|
|
enabled = true
|
|
|
|
}
|
|
|
|
|
2022-07-28 00:02:29 +00:00
|
|
|
jobspec = templatefile("${path.module}/backup.nomad", {
|
2022-11-02 19:32:27 +00:00
|
|
|
module_path = path.module,
|
2022-07-28 00:02:29 +00:00
|
|
|
batch_node = each.key,
|
2023-08-24 19:36:47 +00:00
|
|
|
use_wesher = var.use_wesher
|
2022-07-28 00:02:29 +00:00
|
|
|
})
|
2022-05-18 21:23:28 +00:00
|
|
|
}
|
2023-08-29 19:48:48 +00:00
|
|
|
|
|
|
|
locals {
|
|
|
|
all_job_ids = toset(flatten([[for job in resource.nomad_job.backup-oneoff : job.id], [resource.nomad_job.backup.id]]))
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "nomad_acl_policy" "secrets_mysql" {
|
|
|
|
for_each = local.all_job_ids
|
|
|
|
|
|
|
|
name = "${each.key}-secrets-mysql"
|
|
|
|
description = "Give access to MySQL secrets"
|
|
|
|
rules_hcl = <<EOH
|
|
|
|
namespace "default" {
|
|
|
|
variables {
|
|
|
|
path "secrets/mysql" {
|
|
|
|
capabilities = ["read"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOH
|
|
|
|
|
|
|
|
job_acl {
|
|
|
|
job_id = each.key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "random_password" "mysql_psk" {
|
|
|
|
length = 32
|
|
|
|
override_special = "!@#%&*-_="
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "nomad_variable" "mysql_psk" {
|
|
|
|
path = "secrets/mysql/allowed_psks/backups"
|
|
|
|
items = {
|
|
|
|
psk = "backups:${resource.random_password.mysql_psk.result}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "nomad_acl_policy" "mysql_psk" {
|
|
|
|
for_each = local.all_job_ids
|
|
|
|
|
|
|
|
name = "${each.key}-secrets-mysql-psk"
|
|
|
|
description = "Give access to MySQL PSK secrets"
|
|
|
|
rules_hcl = <<EOH
|
|
|
|
namespace "default" {
|
|
|
|
variables {
|
|
|
|
path "secrets/mysql/allowed_psks/backups" {
|
|
|
|
capabilities = ["read"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOH
|
|
|
|
|
|
|
|
job_acl {
|
|
|
|
job_id = each.key
|
|
|
|
group = "backup"
|
|
|
|
task = "stunnel"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "nomad_acl_policy" "secrets_postgres" {
|
|
|
|
for_each = local.all_job_ids
|
|
|
|
|
|
|
|
name = "${each.key}-secrets-postgres"
|
|
|
|
description = "Give access to Postgres secrets"
|
|
|
|
rules_hcl = <<EOH
|
|
|
|
namespace "default" {
|
|
|
|
variables {
|
|
|
|
path "secrets/postgres" {
|
|
|
|
capabilities = ["read"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOH
|
|
|
|
|
|
|
|
job_acl {
|
|
|
|
job_id = each.key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "random_password" "postgres_psk" {
|
|
|
|
length = 32
|
|
|
|
override_special = "!@#%&*-_="
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "nomad_variable" "postgres_psk" {
|
|
|
|
path = "secrets/postgres/allowed_psks/backups"
|
|
|
|
items = {
|
|
|
|
psk = "backups:${resource.random_password.postgres_psk.result}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "nomad_acl_policy" "postgres_psk" {
|
|
|
|
for_each = local.all_job_ids
|
|
|
|
|
|
|
|
name = "${each.key}-secrets-postgres-psk"
|
|
|
|
description = "Give access to Postgres PSK secrets"
|
|
|
|
rules_hcl = <<EOH
|
|
|
|
namespace "default" {
|
|
|
|
variables {
|
|
|
|
path "secrets/postgres/allowed_psks/backups" {
|
|
|
|
capabilities = ["read"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOH
|
|
|
|
|
|
|
|
job_acl {
|
|
|
|
job_id = each.key
|
|
|
|
group = "backup"
|
|
|
|
task = "stunnel"
|
|
|
|
}
|
|
|
|
}
|