From a30749f3577a2f7111eb94e7052db32e1b731e51 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Fri, 11 Nov 2022 13:34:08 -0800 Subject: [PATCH] Switch services to module based Terraform template from levant This ends up with a better experience in dealing with tfstate for some services. Not sure why. --- .secrets-baseline | 12 +- services/.terraform.lock.hcl | 19 -- services/main.tf | 261 +++++++++++++++++------- services/service/.terraform.lock.hcl | 21 ++ services/service/main.tf | 28 +++ services/service/service_template.nomad | 239 ++++++++++++++++++++++ services/service/vars.tf | 133 ++++++++++++ 7 files changed, 606 insertions(+), 107 deletions(-) create mode 100644 services/service/.terraform.lock.hcl create mode 100644 services/service/main.tf create mode 100644 services/service/service_template.nomad create mode 100644 services/service/vars.tf diff --git a/.secrets-baseline b/.secrets-baseline index 75a7579..7555cef 100644 --- a/.secrets-baseline +++ b/.secrets-baseline @@ -211,17 +211,7 @@ "line_number": 159, "is_secret": false } - ], - "services/main.tf": [ - { - "type": "Secret Keyword", - "filename": "services/main.tf", - "hashed_secret": "f84864c6bffa2e0843a4ab2abdca91df7995c462", - "is_verified": false, - "line_number": 168, - "is_secret": false - } ] }, - "generated_at": "2022-11-10T21:36:17Z" + "generated_at": "2022-11-11T21:26:53Z" } diff --git a/services/.terraform.lock.hcl b/services/.terraform.lock.hcl index 93b826b..4bcdaad 100644 --- a/services/.terraform.lock.hcl +++ b/services/.terraform.lock.hcl @@ -20,25 +20,6 @@ provider "registry.terraform.io/hashicorp/consul" { ] } -provider "registry.terraform.io/hashicorp/external" { - version = "2.2.3" - hashes = [ - "h1:uvOYRWcVIqOZSl8YjjaB18yZFz1AWIt2CnK7O45rckg=", - "zh:184ecd339d764de845db0e5b8a9c87893dcd0c9d822167f73658f89d80ec31c9", - "zh:2661eaca31d17d6bbb18a8f673bbfe3fe1b9b7326e60d0ceb302017003274e3c", - "zh:2c0a180f6d1fc2ba6e03f7dfc5f73b617e45408681f75bca75aa82f3796df0e4", - "zh:4b92ae44c6baef4c4952c47be00541055cb5280dd3bc8031dba5a1b2ee982387", - "zh:5641694d5daf3893d7ea90be03b6fa575211a08814ffe70998d5adb8b59cdc0a", - "zh:5bd55a2be8a1c20d732ac9c604b839e1cadc8c49006315dffa4d709b6874df32", - "zh:6e0ef5d11e1597202424b7d69b9da7b881494c9b13a3d4026fc47012dc651c79", - "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", - "zh:9e19f89fa25004d3b926a8d15ea630b4bde62f1fa4ed5e11a3d27aabddb77353", - "zh:b763efdd69fd097616b4a4c89cf333b4cee9699ac6432d73d2756f8335d1213f", - "zh:e3b561efdee510b2b445f76a52a902c52bee8e13095e7f4bed7c80f10f8d294a", - "zh:fe660bb8781ee043a093b9a20e53069974475dcaa5791a1f45fd03c61a26478a", - ] -} - provider "registry.terraform.io/hashicorp/nomad" { version = "1.4.19" hashes = [ diff --git a/services/main.tf b/services/main.tf index c264926..4b0b2e8 100644 --- a/services/main.tf +++ b/services/main.tf @@ -108,83 +108,190 @@ resource "consul_config_entry" "nzbget_intents" { # } # } -module "photoprism" { - source = "IamTheFij/levant/nomad" - version = "0.1.0" +# resource "nomad_job" "photoprism" { +# jobspec = templatefile("services_tf.nomad", { +# vars = { +# name = "photoprism" +# image = "photoprism/photoprism:latest" +# ingress = true +# service_port = 2342 +# sticky_disk = true +# healthcheck = "/library/login" +# env = { +# PHOTOPRISM_SITE_CAPTION = "AI-Powered Photos App" +# PHOTOPRISM_SITE_DESCRIPTION = "Fijolek home photos" +# PHOTOPRISM_SITE_TITLE = "PhotoPrism" +# PHOTOPRISM_SITE_URL = "https://photoprism.thefij.rocks:2342/" # server URL in the format "http(s)://domain.name(:port)/(path)" +# PHOTOPRISM_SPONSOR = "true" +# # Paths +# PHOTOPRISM_ORIGINALS_PATH = "/photoprism-media/Library" +# PHOTOPRISM_IMPORT_PATH = "/photoprism-media/Import" +# PHOTOPRISM_STORAGE_PATH = "$${NOMAD_TASK_DIR}/storage" # Storage PATH for generated files like cache and index +# # Unix permissions +# PHOTOPRISM_UID = 500 +# PHOTOPRISM_GID = 100 +# PHOTOPRISM_UMASK = 0000 +# } +# mysql = true +# vault = true +# resources = { +# cpu = 100 +# memory = 500 +# memory_max = 1000 +# } +# host_volumes = [ +# { +# name = "photoprism-media" +# dest = "/photoprism-media" +# read_only = false +# }, +# ] +# mysql_bootstrap = { +# vault_key = "kv/data/photoprism" +# } +# templates = [ +# { +# data = < 0]) } + connect { + sidecar_service { + proxy { + local_service_port = ${service_port} + %{ if use_mysql } + upstreams { + destination_name = "mysql-server" + local_bind_port = 4040 + } + %{ endif ~} + %{ if use_redis } + upstreams { + destination_name = "redis" + local_bind_port = 6379 + } + %{ endif ~} + %{ if use_ldap } + upstreams { + destination_name = "lldap" + local_bind_port = 3890 + } + %{ endif ~} + %{ for upstream in upstreams ~} + upstreams { + destination_name = "${upstream.destination_name}" + local_bind_port = ${upstream.local_bind_port} + } + %{ endfor } + } + } + + sidecar_task { + resources { + cpu = 50 + memory = 20 + memory_max = 50 + } + } + } + + %{ endif ~} + %{ if healthcheck_path != null ~} + check { + type = "http" + path = "${healthcheck_path}" + port = "main" + interval = "10s" + timeout = "10s" + } + + %{ endif ~} + tags = [ + %{ if ingress ~} + "traefik.enable=true", + "traefik.http.routers.${name}.entryPoints=websecure", + %{ if try(ingress_rule, null) != null ~} + "traefik.http.routers.${name}.rule=${ingress_rule}", + %{ endif ~} + %{ for middleware in ingress_middlewares ~} + "traefik.http.routers.${name}.middlewares=${middleware}", + %{ endfor ~} + %{ endif ~} + ] + } + + %{ endif ~} + task "${name}" { + driver = "docker" + + config { + image = "${image}" + %{ if service_port != null ~} + ports = ["main"] + %{ endif ~} + %{ if length(try(args, [])) > 0 ~} + args = ${jsonencode(args)} + %{ endif ~} + %{ for template in templates ~} + %{ if template.mount && !template.env ~} + + mount { + type = "bind" + target = "${template.dest}" + source = "${template.dest_prefix}/${template.dest}" + } + %{ endif ~} + %{ endfor ~} + } + %{ if use_vault ~} + + vault { + policies = [ + "access-tables", + "nomad-task", + ] + } + %{ endif ~} + %{ if length(env) > 0 ~} + + env = { + %{ for k, v in env ~} + "${k}" = "${v}" + %{ endfor } + } + %{ endif ~} + %{ for volume in host_volumes ~} + + volume_mount { + volume = "${volume.name}" + destination = "${volume.dest}" + read_only = ${volume.read_only} + } + %{ endfor ~} + %{ for template in templates ~} + + template { + data = <