diff --git a/2-nomad-config/1-infra.tf b/2-nomad-config/1-infra.tf deleted file mode 100644 index 2a978e7..0000000 --- a/2-nomad-config/1-infra.tf +++ /dev/null @@ -1,141 +0,0 @@ -terraform { - backend "local" { - path = "./.tfstate/terraform.tfstate" - } -} - -terraform { - required_providers { - sops = { - source = "carlpett/sops" - version = "~> 0.5" - } - cloudflare = { - source = "cloudflare/cloudflare" - version = "~> 5" - } - postgresql = { - source = "cyrilgdn/postgresql" - } - } -} - -provider "nomad" { - address = "http://jaglan-beta-m01.othrayte.one:4646" -} - -data "sops_file" "secrets" { - source_file = "secrets.enc.json" -} - -provider "cloudflare" { - api_token = data.sops_file.secrets.data["cloudflare.api_token"] -} - -// Networking - -resource "cloudflare_dns_record" "othrayte-one" { - comment = "othrayte.one proxy to internal IP for traefik" - zone_id = "2616ab2a44d0645b03fbc3106c79bd99" - type = "AAAA" - name = "othrayte.one" - content = data.sops_file.secrets.data["cloudflare.direct_ip6"] - proxied = true - ttl = 1 # Auto -} - -resource "cloudflare_dns_record" "star-othrayte-one" { - comment = "*.othrayte.one proxy to internal IP for traefik" - zone_id = "2616ab2a44d0645b03fbc3106c79bd99" - type = "AAAA" - name = "*" - content = data.sops_file.secrets.data["cloudflare.direct_ip6"] - proxied = true - ttl = 1 # Auto -} - -resource "nomad_job" "traefik" { - jobspec = file("traefik.nomad.hcl") -} - -// Authentication - -resource "nomad_job" "authelia" { - jobspec = file("authelia.nomad.hcl") -} - -resource "nomad_variable" "authelia" { - path = "nomad/jobs/authelia" - items = { - session_secret = data.sops_file.secrets.data["authelia.session_secret"] - jwt_secret = data.sops_file.secrets.data["authelia.jwt_secret"] - encryption_key = data.sops_file.secrets.data["authelia.encryption_key"] - } -} - -// Data - -resource "nomad_job" "csi-smb" { - jobspec = file("csi-smb.nomad.hcl") -} - -data "nomad_plugin" "smb" { - plugin_id = "smb" - wait_for_healthy = true -} - -resource "nomad_job" "postgres" { - jobspec = file("postgres.nomad.hcl") -} - -resource "nomad_job" "pgadmin" { - jobspec = file("pgadmin.nomad.hcl") -} - -resource "nomad_job" "pgbackup" { - jobspec = file("pgbackup.nomad.hcl") -} - -resource "nomad_variable" "postgres" { - path = "nomad/jobs/postgres" - items = { - postgres_password = data.sops_file.secrets.data["postgres.postgres"] - } -} - -provider "postgresql" { - #host = "jaglan-beta-m01.othrayte.one" - host = "192.168.1.235" - port = 5432 - database = "postgres" - username = "postgres" - password = data.sops_file.secrets.data["postgres.postgres"] - sslmode = "disable" - connect_timeout = 15 -} - -resource "nomad_csi_volume_registration" "unraid_database_dump" { - #Note: Before chaning the definition of this volume you need to stop the jobs that are using it - depends_on = [data.nomad_plugin.smb] - plugin_id = "smb" - - volume_id = "unraid_database_dump" - name = "unraid_database_dump" - - external_id = "unraid_database_dump" - - capability { - access_mode = "single-node-writer" - attachment_mode = "file-system" - } - - context = { - source = "//192.168.1.192/database-dump" - } - - secrets = { - "username" = "nomad" - "password" = data.sops_file.secrets.data["unraid.nomad"] - } -} - diff --git a/2-nomad-config/authelia.tf b/2-nomad-config/authelia.tf new file mode 100644 index 0000000..e13f9f9 --- /dev/null +++ b/2-nomad-config/authelia.tf @@ -0,0 +1,12 @@ +resource "nomad_job" "authelia" { + jobspec = file("authelia.nomad.hcl") +} + +resource "nomad_variable" "authelia" { + path = "nomad/jobs/authelia" + items = { + session_secret = data.sops_file.secrets.data["authelia.session_secret"] + jwt_secret = data.sops_file.secrets.data["authelia.jwt_secret"] + encryption_key = data.sops_file.secrets.data["authelia.encryption_key"] + } +} diff --git a/2-nomad-config/2-services.tf b/2-nomad-config/gitea.tf similarity index 50% rename from 2-nomad-config/2-services.tf rename to 2-nomad-config/gitea.tf index 81b72d5..49e2496 100644 --- a/2-nomad-config/2-services.tf +++ b/2-nomad-config/gitea.tf @@ -1,68 +1,8 @@ -resource "nomad_job" "glance" { - jobspec = file("glance.nomad.hcl") -} - -resource "nomad_job" "transfer" { - jobspec = file("transfer.nomad.hcl") -} - -resource "nomad_csi_volume_registration" "unraid_transfer" { - #Note: Before chaning the definition of this volume you need to stop the jobs that are using it - depends_on = [data.nomad_plugin.smb] - plugin_id = "smb" - - volume_id = "unraid_transfer" - name = "unraid_transfer" - - external_id = "unraid_transfer" - - capability { - access_mode = "single-node-writer" - attachment_mode = "file-system" - } - - context = { - source = "//192.168.1.192/transfer" - } - - secrets = { - "username" = "anon" - "password" = "" - } -} - - -resource "nomad_csi_volume_registration" "unraid_appdata_transferfilebrowser" { - #Note: Before chaning the definition of this volume you need to stop the jobs that are using it - depends_on = [data.nomad_plugin.smb] - plugin_id = "smb" - - volume_id = "unraid_appdata_transferfilebrowser" - name = "unraid_appdata_transferfilebrowser" - - external_id = "unraid_appdata_transferfilebrowser" - - capability { - access_mode = "single-node-writer" - attachment_mode = "file-system" - } - - context = { - source = "//192.168.1.192/appdata" - subDir = "transferfilebrowser" # Note: Needs to be manually created on the share - } - - secrets = { - "username" = "nomad" - "password" = data.sops_file.secrets.data["unraid.nomad"] - } -} - resource "cloudflare_dns_record" "git-othrayte-one" { comment = "git.othrayte.one maps to tailscale fqdn" zone_id = "2616ab2a44d0645b03fbc3106c79bd99" type = "CNAME" - name = "git" + name = "git.othrayte.one" content = "git.tail15856.ts.net" ttl = 1 # Auto } @@ -117,5 +57,3 @@ resource "nomad_csi_volume_registration" "unraid_appdata_gitea" { "password" = data.sops_file.secrets.data["unraid.nomad"] } } - - diff --git a/2-nomad-config/glance.tf b/2-nomad-config/glance.tf new file mode 100644 index 0000000..670949a --- /dev/null +++ b/2-nomad-config/glance.tf @@ -0,0 +1,3 @@ +resource "nomad_job" "glance" { + jobspec = file("glance.nomad.hcl") +} diff --git a/2-nomad-config/main.tf b/2-nomad-config/main.tf new file mode 100644 index 0000000..c50fc69 --- /dev/null +++ b/2-nomad-config/main.tf @@ -0,0 +1,42 @@ +terraform { + backend "local" { + path = "./.tfstate/terraform.tfstate" + } +} + +terraform { + required_providers { + sops = { + source = "carlpett/sops" + version = "~> 0.5" + } + cloudflare = { + source = "cloudflare/cloudflare" + version = "~> 5" + } + postgresql = { + source = "cyrilgdn/postgresql" + } + } +} + +provider "nomad" { + address = "http://jaglan-beta-m01.othrayte.one:4646" +} + +data "sops_file" "secrets" { + source_file = "secrets.enc.json" +} + +provider "cloudflare" { + api_token = data.sops_file.secrets.data["cloudflare.api_token"] +} + +resource "nomad_job" "csi-smb" { + jobspec = file("csi-smb.nomad.hcl") +} + +data "nomad_plugin" "smb" { + plugin_id = "smb" + wait_for_healthy = true +} diff --git a/2-nomad-config/postgres.tf b/2-nomad-config/postgres.tf new file mode 100644 index 0000000..55a1a65 --- /dev/null +++ b/2-nomad-config/postgres.tf @@ -0,0 +1,54 @@ +resource "nomad_job" "postgres" { + jobspec = file("postgres.nomad.hcl") +} + +resource "nomad_job" "pgadmin" { + jobspec = file("pgadmin.nomad.hcl") +} + +resource "nomad_job" "pgbackup" { + jobspec = file("pgbackup.nomad.hcl") +} + +resource "nomad_variable" "postgres" { + path = "nomad/jobs/postgres" + items = { + postgres_password = data.sops_file.secrets.data["postgres.postgres"] + } +} + +provider "postgresql" { + #host = "jaglan-beta-m01.othrayte.one" + host = "192.168.1.235" + port = 5432 + database = "postgres" + username = "postgres" + password = data.sops_file.secrets.data["postgres.postgres"] + sslmode = "disable" + connect_timeout = 15 +} + +resource "nomad_csi_volume_registration" "unraid_database_dump" { + #Note: Before chaning the definition of this volume you need to stop the jobs that are using it + depends_on = [data.nomad_plugin.smb] + plugin_id = "smb" + + volume_id = "unraid_database_dump" + name = "unraid_database_dump" + + external_id = "unraid_database_dump" + + capability { + access_mode = "single-node-writer" + attachment_mode = "file-system" + } + + context = { + source = "//192.168.1.192/database-dump" + } + + secrets = { + "username" = "nomad" + "password" = data.sops_file.secrets.data["unraid.nomad"] + } +} diff --git a/2-nomad-config/traefik.tf b/2-nomad-config/traefik.tf new file mode 100644 index 0000000..009c75d --- /dev/null +++ b/2-nomad-config/traefik.tf @@ -0,0 +1,23 @@ +resource "cloudflare_dns_record" "othrayte-one" { + comment = "othrayte.one proxy to internal IP for traefik" + zone_id = "2616ab2a44d0645b03fbc3106c79bd99" + type = "AAAA" + name = "othrayte.one" + content = data.sops_file.secrets.data["cloudflare.direct_ip6"] + proxied = true + ttl = 1 # Auto +} + +resource "cloudflare_dns_record" "star-othrayte-one" { + comment = "*.othrayte.one proxy to internal IP for traefik" + zone_id = "2616ab2a44d0645b03fbc3106c79bd99" + type = "AAAA" + name = "*.othrayte.one" + content = data.sops_file.secrets.data["cloudflare.direct_ip6"] + proxied = true + ttl = 1 # Auto +} + +resource "nomad_job" "traefik" { + jobspec = file("traefik.nomad.hcl") +} diff --git a/2-nomad-config/transfer.tf b/2-nomad-config/transfer.tf new file mode 100644 index 0000000..2e08daa --- /dev/null +++ b/2-nomad-config/transfer.tf @@ -0,0 +1,54 @@ +resource "nomad_job" "transfer" { + jobspec = file("transfer.nomad.hcl") +} + +resource "nomad_csi_volume_registration" "unraid_transfer" { + #Note: Before chaning the definition of this volume you need to stop the jobs that are using it + depends_on = [data.nomad_plugin.smb] + plugin_id = "smb" + + volume_id = "unraid_transfer" + name = "unraid_transfer" + + external_id = "unraid_transfer" + + capability { + access_mode = "single-node-writer" + attachment_mode = "file-system" + } + + context = { + source = "//192.168.1.192/transfer" + } + + secrets = { + "username" = "anon" + "password" = "" + } +} + +resource "nomad_csi_volume_registration" "unraid_appdata_transferfilebrowser" { + #Note: Before chaning the definition of this volume you need to stop the jobs that are using it + depends_on = [data.nomad_plugin.smb] + plugin_id = "smb" + + volume_id = "unraid_appdata_transferfilebrowser" + name = "unraid_appdata_transferfilebrowser" + + external_id = "unraid_appdata_transferfilebrowser" + + capability { + access_mode = "single-node-writer" + attachment_mode = "file-system" + } + + context = { + source = "//192.168.1.192/appdata" + subDir = "transferfilebrowser" # Note: Needs to be manually created on the share + } + + secrets = { + "username" = "nomad" + "password" = data.sops_file.secrets.data["unraid.nomad"] + } +}