From 2e61e7ef3c32826cd6df8a62e91e96dd6ea175e1 Mon Sep 17 00:00:00 2001 From: main Date: Sat, 30 Jul 2022 23:27:40 +0200 Subject: [PATCH] Reorganization and better Terraform Signed-off-by: main --- infrastructure/camptules/camptules-policy.hcl | 3 - infrastructure/camptules/main.tf | 29 - infrastructure/email/dovecot-policy.hcl | 3 - infrastructure/email/getmail-policy.hcl | 3 - infrastructure/gitea/gitea-policy.hcl | 3 - .../home-assistant/home-assistant-policy.hcl | 3 - .../home-assistant/mosquitto-policy.hcl | 3 - .../home-assistant/zigbee2mqtt-policy.hcl | 7 - infrastructure/hydra/hydra-policy.hcl | 3 - infrastructure/ingress/nomad.hcl | 583 ------------------ infrastructure/main.tf | 101 --- infrastructure/mesh/main.tf | 19 - infrastructure/minecraft/minecraft.hcl | 19 - infrastructure/minecraft/nomad.hcl | 58 -- infrastructure/plugin-nfs/main.tf | 31 - infrastructure/plugin-nfs/nfs-nodes.hcl | 43 -- infrastructure/reicio/main.tf | 19 - infrastructure/syncthing/nomad.hcl | 111 ---- infrastructure/website/main.tf | 24 - main.tf | 17 + nomad/main.tf | 24 + .../modules/gateway-mesh/main.hcl | 13 +- nomad/modules/gateway-mesh/main.tf | 20 + .../modules/nfs/controller.hcl | 15 +- nomad/modules/nfs/main.tf | 42 ++ nomad/modules/nfs/node.hcl | 44 ++ nomad/regions/do-1/ingress-upstreams.conf | 83 +++ nomad/regions/do-1/ingress.hcl | 219 +++++++ .../main.tf => nomad/regions/do-1/ingress.tf | 15 +- nomad/regions/do-1/main.tf | 43 ++ nomad/regions/homelab-1/baikal.tf | 57 ++ nomad/regions/homelab-1/camptules.tf | 20 + .../regions/homelab-1/email.tf | 30 +- .../regions/homelab-1/gitea.tf | 29 +- .../regions/homelab-1/home-assistant.tf | 43 +- .../regions/homelab-1/hydra.tf | 29 +- .../regions/homelab-1/ingress-upstreams.conf | 139 +++++ nomad/regions/homelab-1/ingress.tf | 17 + .../regions/homelab-1/jellyfin.tf | 24 +- nomad/regions/homelab-1/job/baikal.hcl | 96 +++ .../regions/homelab-1/job/camptules.hcl | 22 +- .../regions/homelab-1/job/email.hcl | 68 +- .../regions/homelab-1/job/gitea.hcl | 60 +- .../regions/homelab-1/job/home-assistant.hcl | 134 ++-- .../regions/homelab-1/job/hydra.hcl | 104 ++-- nomad/regions/homelab-1/job/ingress.hcl | 184 ++++++ .../regions/homelab-1/job/jellyfin.hcl | 92 +-- .../regions/homelab-1/job}/reicio.hcl | 28 +- nomad/regions/homelab-1/job/syncthing.hcl | 111 ++++ .../regions/homelab-1/job/website.hcl | 44 +- nomad/regions/homelab-1/main.tf | 42 ++ nomad/regions/homelab-1/reicio.tf | 11 + .../regions/homelab-1/syncthing.tf | 21 +- nomad/regions/homelab-1/website.tf | 11 + nomad/regions/main.tf | 33 + 55 files changed, 1572 insertions(+), 1477 deletions(-) delete mode 100644 infrastructure/camptules/camptules-policy.hcl delete mode 100644 infrastructure/camptules/main.tf delete mode 100644 infrastructure/email/dovecot-policy.hcl delete mode 100644 infrastructure/email/getmail-policy.hcl delete mode 100644 infrastructure/gitea/gitea-policy.hcl delete mode 100644 infrastructure/home-assistant/home-assistant-policy.hcl delete mode 100644 infrastructure/home-assistant/mosquitto-policy.hcl delete mode 100644 infrastructure/home-assistant/zigbee2mqtt-policy.hcl delete mode 100644 infrastructure/hydra/hydra-policy.hcl delete mode 100644 infrastructure/ingress/nomad.hcl delete mode 100644 infrastructure/main.tf delete mode 100644 infrastructure/mesh/main.tf delete mode 100644 infrastructure/minecraft/minecraft.hcl delete mode 100644 infrastructure/minecraft/nomad.hcl delete mode 100644 infrastructure/plugin-nfs/main.tf delete mode 100644 infrastructure/plugin-nfs/nfs-nodes.hcl delete mode 100644 infrastructure/reicio/main.tf delete mode 100644 infrastructure/syncthing/nomad.hcl delete mode 100644 infrastructure/website/main.tf create mode 100644 nomad/main.tf rename infrastructure/mesh/nomad.hcl => nomad/modules/gateway-mesh/main.hcl (66%) create mode 100644 nomad/modules/gateway-mesh/main.tf rename infrastructure/plugin-nfs/nfs-controller.hcl => nomad/modules/nfs/controller.hcl (56%) create mode 100644 nomad/modules/nfs/main.tf create mode 100644 nomad/modules/nfs/node.hcl create mode 100644 nomad/regions/do-1/ingress-upstreams.conf create mode 100644 nomad/regions/do-1/ingress.hcl rename infrastructure/ingress/main.tf => nomad/regions/do-1/ingress.tf (69%) create mode 100644 nomad/regions/do-1/main.tf create mode 100644 nomad/regions/homelab-1/baikal.tf create mode 100644 nomad/regions/homelab-1/camptules.tf rename infrastructure/email/main.tf => nomad/regions/homelab-1/email.tf (70%) rename infrastructure/gitea/main.tf => nomad/regions/homelab-1/gitea.tf (64%) rename infrastructure/home-assistant/main.tf => nomad/regions/homelab-1/home-assistant.tf (73%) rename infrastructure/hydra/main.tf => nomad/regions/homelab-1/hydra.tf (77%) create mode 100644 nomad/regions/homelab-1/ingress-upstreams.conf create mode 100644 nomad/regions/homelab-1/ingress.tf rename infrastructure/jellyfin/main.tf => nomad/regions/homelab-1/jellyfin.tf (71%) create mode 100644 nomad/regions/homelab-1/job/baikal.hcl rename infrastructure/camptules/nomad.hcl => nomad/regions/homelab-1/job/camptules.hcl (60%) rename infrastructure/email/nomad.hcl => nomad/regions/homelab-1/job/email.hcl (63%) rename infrastructure/gitea/nomad.hcl => nomad/regions/homelab-1/job/gitea.hcl (62%) rename infrastructure/home-assistant/nomad.hcl => nomad/regions/homelab-1/job/home-assistant.hcl (56%) rename infrastructure/hydra/nomad.hcl => nomad/regions/homelab-1/job/hydra.hcl (57%) create mode 100644 nomad/regions/homelab-1/job/ingress.hcl rename infrastructure/jellyfin/nomad.hcl => nomad/regions/homelab-1/job/jellyfin.hcl (52%) rename {infrastructure/reicio => nomad/regions/homelab-1/job}/reicio.hcl (54%) create mode 100644 nomad/regions/homelab-1/job/syncthing.hcl rename infrastructure/website/nomad.hcl => nomad/regions/homelab-1/job/website.hcl (51%) create mode 100644 nomad/regions/homelab-1/main.tf create mode 100644 nomad/regions/homelab-1/reicio.tf rename infrastructure/syncthing/main.tf => nomad/regions/homelab-1/syncthing.tf (75%) create mode 100644 nomad/regions/homelab-1/website.tf create mode 100644 nomad/regions/main.tf diff --git a/infrastructure/camptules/camptules-policy.hcl b/infrastructure/camptules/camptules-policy.hcl deleted file mode 100644 index b9c0162..0000000 --- a/infrastructure/camptules/camptules-policy.hcl +++ /dev/null @@ -1,3 +0,0 @@ -path "kv/data/camptules" { - capabilities = ["read"] -} diff --git a/infrastructure/camptules/main.tf b/infrastructure/camptules/main.tf deleted file mode 100644 index 1a82692..0000000 --- a/infrastructure/camptules/main.tf +++ /dev/null @@ -1,29 +0,0 @@ -variable "flake_ref" { - type = string -} - -variable "flake_sha" { - type = string -} - -# data "nomad_plugin" "nomad-driver-containerd" { -# plugin_id = "nomad-driver-containerd" -# wait_for_healthy = true -# } - -resource "vault_policy" "camputules-policy" { - name = "camptules-policy" - policy = file("${path.module}/camptules-policy.hcl") -} - -resource "nomad_job" "camptules" { - jobspec = file("${path.module}/nomad.hcl") - - hcl2 { - enabled = true - vars = { - flake_ref = var.flake_ref - flake_sha = var.flake_sha - } - } -} diff --git a/infrastructure/email/dovecot-policy.hcl b/infrastructure/email/dovecot-policy.hcl deleted file mode 100644 index 836f85c..0000000 --- a/infrastructure/email/dovecot-policy.hcl +++ /dev/null @@ -1,3 +0,0 @@ -path "kv/data/dovecot" { - capabilities = ["read"] -} diff --git a/infrastructure/email/getmail-policy.hcl b/infrastructure/email/getmail-policy.hcl deleted file mode 100644 index cfaf290..0000000 --- a/infrastructure/email/getmail-policy.hcl +++ /dev/null @@ -1,3 +0,0 @@ -path "kv/data/getmail" { - capabilities = ["read"] -} diff --git a/infrastructure/gitea/gitea-policy.hcl b/infrastructure/gitea/gitea-policy.hcl deleted file mode 100644 index e3eab31..0000000 --- a/infrastructure/gitea/gitea-policy.hcl +++ /dev/null @@ -1,3 +0,0 @@ -path "kv/data/gitea" { - capabilities = ["read"] -} diff --git a/infrastructure/home-assistant/home-assistant-policy.hcl b/infrastructure/home-assistant/home-assistant-policy.hcl deleted file mode 100644 index 31c8136..0000000 --- a/infrastructure/home-assistant/home-assistant-policy.hcl +++ /dev/null @@ -1,3 +0,0 @@ -path "kv/data/home-assistant" { - capabilities = ["read"] -} diff --git a/infrastructure/home-assistant/mosquitto-policy.hcl b/infrastructure/home-assistant/mosquitto-policy.hcl deleted file mode 100644 index dbc9a00..0000000 --- a/infrastructure/home-assistant/mosquitto-policy.hcl +++ /dev/null @@ -1,3 +0,0 @@ -path "kv/data/mqtt" { - capabilities = ["read"] -} diff --git a/infrastructure/home-assistant/zigbee2mqtt-policy.hcl b/infrastructure/home-assistant/zigbee2mqtt-policy.hcl deleted file mode 100644 index 40150fd..0000000 --- a/infrastructure/home-assistant/zigbee2mqtt-policy.hcl +++ /dev/null @@ -1,7 +0,0 @@ -path "kv/data/mqtt" { - capabilities = ["read"] -} - -path "kv/data/zigbee2mqtt" { - capabilities = ["read"] -} diff --git a/infrastructure/hydra/hydra-policy.hcl b/infrastructure/hydra/hydra-policy.hcl deleted file mode 100644 index 8b62445..0000000 --- a/infrastructure/hydra/hydra-policy.hcl +++ /dev/null @@ -1,3 +0,0 @@ -path "kv/data/hydra" { - capabilities = ["read"] -} diff --git a/infrastructure/ingress/nomad.hcl b/infrastructure/ingress/nomad.hcl deleted file mode 100644 index 6408295..0000000 --- a/infrastructure/ingress/nomad.hcl +++ /dev/null @@ -1,583 +0,0 @@ -variable "flake_ref" { - type = string -} - -variable "flake_sha" { - type = string -} - -job "ingress" { - datacenters = [ "do-1", "homelab-1" ] - type = "service" - - group "ingress-toothpick" { - count = 1 - - constraint { - attribute = "${attr.unique.hostname}" - value = "toothpick" - } - - volume "ingress-letsencrypt" { - type = "csi" - source = "ingress-letsencrypt" - read_only = false - - attachment_mode = "file-system" - access_mode = "single-node-writer" - } - - network { - mode = "bridge" - port "http" { - static = 80 - to = 80 - host_network = "public" - } - - port "https" { - static = 443 - to = 443 - host_network = "public" - } - - port "minecraft" { - static = 25565 - to = 25565 - host_network = "public" - } - } - - service { - name = "ingress-toothpick" - port = "http" - - connect { - sidecar_service { - proxy { - upstreams { - destination_name = "gitea" - local_bind_port = 3000 - datacenter = "homelab-1" - - mesh_gateway { - mode = "local" - } - } - - upstreams { - destination_name = "hydra" - local_bind_port = 8666 - datacenter = "homelab-1" - - mesh_gateway { - mode = "local" - } - } - - upstreams { - destination_name = "nextcloud" - local_bind_port = 8777 - datacenter = "homelab-1" - - mesh_gateway { - mode = "local" - } - } - - upstreams { - destination_name = "website" - local_bind_port = 8080 - datacenter = "homelab-1" - - mesh_gateway { - mode = "local" - } - } - - upstreams { - destination_name = "minecraft" - local_bind_port = 2666 - datacenter = "homelab-1" - - mesh_gateway { - mode = "local" - } - } - - upstreams { - destination_name = "reicio" - local_bind_port = 8000 - datacenter = "homelab-1" - - mesh_gateway { - mode = "local" - } - } - } - } - } - } - - task "nginx" { - driver = "docker" - - volume_mount { - volume = "ingress-letsencrypt" - destination = "/etc/letsencrypt" - read_only = false - } - - # artifact { - # source = "http://hydra/build/99/download/1/image.tar.gz" - # } - - config { - # load = "nixng-ingress.tar.gz" - image = "nixng-ingress:local" - - ports = ["http", "https", "minecraft"] - memory_hard_limit = 128 - } - - resources { - cpu = 200 - memory = 32 - } - - template { - data = <