Make appdata and unraid smb modules to reduce duplication

This commit is contained in:
2025-11-20 23:45:16 +11:00
parent 961ec128f1
commit d3ac8a252b
12 changed files with 191 additions and 407 deletions

View File

@@ -18,27 +18,9 @@ resource "nomad_variable" "postgres" {
}
}
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 = "//betelgeuse-seven-unraid.lan/database-dump"
}
secrets = {
"username" = "nomad"
"password" = data.sops_file.secrets.data["unraid.nomad"]
}
module "unraid_smb_database_dump" {
source = "../modules/unraid_smb"
name = "dump"
id = "unraid_database_dump"
share = "database-dump"
}

View File

@@ -32,28 +32,8 @@ resource "nomad_job" "traefik" {
})
}
resource "nomad_csi_volume_registration" "unraid_appdata_traefik" {
#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_traefik"
name = "unraid_appdata_traefik"
external_id = "unraid_appdata_traefik"
capability {
module "appdata_traefik" {
source = "../modules/appdata"
name = "traefik"
access_mode = "multi-node-multi-writer"
attachment_mode = "file-system"
}
context = {
source = "//betelgeuse-seven-unraid.lan/appdata"
subDir = "traefik" # Note: Needs to be manually created on the share
}
secrets = {
"username" = "nomad"
"password" = data.sops_file.secrets.data["unraid.nomad"]
}
}

View File

@@ -11,54 +11,14 @@ resource "nomad_variable" "deluge" {
}
}
resource "nomad_csi_volume_registration" "unraid_appdata_deluge" {
#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_deluge"
name = "unraid_appdata_deluge"
external_id = "unraid_appdata_deluge"
capability {
access_mode = "single-node-writer"
attachment_mode = "file-system"
module "appdata_deluge" {
source = "./modules/appdata"
name = "deluge"
}
context = {
source = "//betelgeuse-seven-unraid.lan/appdata"
subDir = "deluge" # Note: Needs to be manually created on the share
}
secrets = {
"username" = "nomad"
"password" = data.sops_file.secrets.data["unraid.nomad"]
}
}
resource "nomad_csi_volume_registration" "unraid_media_deluge" {
#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_media_deluge"
name = "unraid_media_deluge"
external_id = "unraid_media_deluge"
capability {
access_mode = "single-node-writer"
attachment_mode = "file-system"
}
context = {
source = "//betelgeuse-seven-unraid.lan/media"
module "unraid_smb_deluge_media" {
source = "./modules/unraid_smb"
name = "deluge"
share = "media"
subDir = "downloads"
}
secrets = {
"username" = "nomad"
"password" = data.sops_file.secrets.data["unraid.nomad"]
}
}

View File

@@ -33,28 +33,7 @@ resource "postgresql_database" "gitea" {
owner = postgresql_role.gitea.name
}
resource "nomad_csi_volume_registration" "unraid_appdata_gitea" {
#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_gitea"
name = "unraid_appdata_gitea"
external_id = "unraid_appdata_gitea"
capability {
access_mode = "single-node-writer"
attachment_mode = "file-system"
}
context = {
source = "//betelgeuse-seven-unraid.lan/appdata"
subDir = "gitea" # Note: Needs to be manually created on the share
}
secrets = {
"username" = "nomad"
"password" = data.sops_file.secrets.data["unraid.nomad"]
}
module "appdata_gitea" {
source = "./modules/appdata"
name = "gitea"
}

View File

@@ -34,107 +34,29 @@ resource "nomad_variable" "immich" {
}
}
resource "nomad_csi_volume_registration" "unraid_appdata_immich" {
#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_immich"
name = "unraid_appdata_immich"
external_id = "unraid_appdata_immich"
capability {
access_mode = "single-node-writer"
attachment_mode = "file-system"
module "appdata_immich" {
source = "./modules/appdata"
name = "immich"
}
context = {
source = "//betelgeuse-seven-unraid.lan/appdata"
subDir = "immich" # Note: Needs to be manually created on the share
module "unraid_smb_immich_photosvideos" {
source = "./modules/unraid_smb"
name = "photosvideos"
share = "media"
subDir = "Photos and Videos"
}
secrets = {
"username" = "nomad"
"password" = data.sops_file.secrets.data["unraid.nomad"]
}
module "unraid_smb_immich_encodedvideo" {
source = "./modules/unraid_smb"
name = "immich_encodedvideo"
share = "media"
subDir = "immich/encoded-video"
}
resource "nomad_csi_volume_registration" "unraid_media_photosvideos" {
#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_media_photosvideos"
name = "unraid_media_photosvideos"
external_id = "unraid_media_photosvideos"
capability {
access_mode = "single-node-writer"
attachment_mode = "file-system"
module "unraid_smb_immich_mediadump_photosvideos" {
source = "./modules/unraid_smb"
name = "photosvideos"
id = "unraid_mediadump_photosvideos"
share = "media-dump"
subDir = "Photos and Videos"
}
context = {
source = "//betelgeuse-seven-unraid.lan/media"
subDir = "Photos and Videos" # Note: Needs to be manually created on the share
}
secrets = {
"username" = "nomad"
"password" = data.sops_file.secrets.data["unraid.nomad"]
}
}
resource "nomad_csi_volume_registration" "unraid_media_immich_encodedvideo" {
#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_media_immich_encodedvideo"
name = "unraid_media_immich_encodedvideo"
external_id = "unraid_media_immich_encodedvideo"
capability {
access_mode = "single-node-writer"
attachment_mode = "file-system"
}
context = {
source = "//betelgeuse-seven-unraid.lan/media"
subDir = "immich/encoded-video" # Note: Needs to be manually created on the share
}
secrets = {
"username" = "nomad"
"password" = data.sops_file.secrets.data["unraid.nomad"]
}
}
resource "nomad_csi_volume_registration" "unraid_mediadump_photosvideos" {
#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_mediadump_photosvideos"
name = "unraid_mediadump_photosvideos"
external_id = "unraid_mediadump_photosvideos"
capability {
access_mode = "single-node-writer"
attachment_mode = "file-system"
}
context = {
source = "//betelgeuse-seven-unraid.lan/media-dump"
subDir = "Photos and Videos" # Note: Needs to be manually created on the share
}
secrets = {
"username" = "nomad"
"password" = data.sops_file.secrets.data["unraid.nomad"]
}
}

View File

@@ -3,53 +3,13 @@ resource "nomad_job" "jellyfin" {
jobspec = file("jellyfin.nomad.hcl")
}
resource "nomad_csi_volume_registration" "unraid_appdata_jellyfin" {
#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_jellyfin"
name = "unraid_appdata_jellyfin"
external_id = "unraid_appdata_jellyfin"
capability {
access_mode = "single-node-writer"
attachment_mode = "file-system"
module "appdata_jellyfin" {
source = "./modules/appdata"
name = "jellyfin"
}
context = {
source = "//betelgeuse-seven-unraid.lan/appdata"
subDir = "jellyfin" # Note: Needs to be manually created on the share
}
secrets = {
"username" = "nomad"
"password" = data.sops_file.secrets.data["unraid.nomad"]
}
}
resource "nomad_csi_volume_registration" "unraid_media_jellyfin" {
#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_media_jellyfin"
name = "unraid_media_jellyfin"
external_id = "unraid_media_jellyfin"
capability {
access_mode = "single-node-writer"
attachment_mode = "file-system"
}
context = {
source = "//betelgeuse-seven-unraid.lan/media"
}
secrets = {
"username" = "nomad"
"password" = data.sops_file.secrets.data["unraid.nomad"]
}
module "unraid_smb_jellyfin_media" {
source = "./modules/unraid_smb"
name = "jellyfin"
share = "media"
}

View File

@@ -0,0 +1,62 @@
terraform {
required_providers {
sops = {
source = "carlpett/sops"
version = "~> 0.5"
}
}
}
variable "name" {
description = "Name of the application, also used as subdir on the unraid appdata share"
type = string
}
variable "id" {
description = "ID to use for the volume registration, defaults to name with - replaced by _"
type = string
default = null
}
variable "access_mode" {
description = "CSI volume access mode"
type = string
default = "single-node-writer"
validation {
condition = contains(["single-node-writer", "multi-node-multi-writer"], var.access_mode)
error_message = "access_mode must be either 'single-node-writer' or 'multi-node-multi-writer'"
}
}
data "nomad_plugin" "smb" {
plugin_id = "smb"
wait_for_healthy = true
}
data "sops_file" "secrets" {
source_file = "secrets/secrets.enc.json"
}
resource "nomad_csi_volume_registration" "this" {
depends_on = [data.nomad_plugin.smb]
plugin_id = "smb"
volume_id = var.id != null ? var.id : "unraid_appdata_${replace(var.name, "-", "_")}"
name = var.id != null ? var.id : "unraid_appdata_${replace(var.name, "-", "_")}"
external_id = var.id != null ? var.id : "unraid_appdata_${replace(var.name, "-", "_")}"
capability {
access_mode = var.access_mode
attachment_mode = "file-system"
}
context = {
source = "//betelgeuse-seven-unraid.lan/appdata"
subDir = var.name
}
secrets = {
"username" = "nomad"
"password" = data.sops_file.secrets.data["unraid.nomad"]
}
}

View File

@@ -0,0 +1,62 @@
terraform {
required_providers {
sops = {
source = "carlpett/sops"
version = "~> 0.5"
}
}
}
variable "name" {
description = "Name of the volume registration"
type = string
}
variable "id" {
description = "ID to use for the volume registration, defaults to name with - replaced by _"
type = string
default = null
}
variable "share" {
description = "Name of the SMB share on the unraid server"
type = string
}
variable "subDir" {
description = "Subdirectory within the SMB share"
type = string
default = null
}
data "nomad_plugin" "smb" {
plugin_id = "smb"
wait_for_healthy = true
}
data "sops_file" "secrets" {
source_file = "secrets/secrets.enc.json"
}
resource "nomad_csi_volume_registration" "this" {
depends_on = [data.nomad_plugin.smb]
plugin_id = "smb"
volume_id = var.id != null ? var.id : "unraid_${var.share}_${replace(var.name, "-", "_")}"
name = var.id != null ? var.id : "unraid_${var.share}_${replace(var.name, "-", "_")}"
external_id = var.id != null ? var.id : "unraid_${var.share}_${replace(var.name, "-", "_")}"
capability {
access_mode = "single-node-writer"
attachment_mode = "file-system"
}
context = merge({
source = "//betelgeuse-seven-unraid.lan/${var.share}"
}, var.subDir == null ? {} : { "subDir" = var.subDir })
secrets = {
"username" = "nomad"
"password" = data.sops_file.secrets.data["unraid.nomad"]
}
}

View File

@@ -26,28 +26,7 @@ resource "postgresql_database" "prowlarr_log" {
owner = postgresql_role.prowlarr.name
}
resource "nomad_csi_volume_registration" "unraid_appdata_prowlarr" {
#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_prowlarr"
name = "unraid_appdata_prowlarr"
external_id = "unraid_appdata_prowlarr"
capability {
access_mode = "single-node-writer"
attachment_mode = "file-system"
}
context = {
source = "//betelgeuse-seven-unraid.lan/appdata"
subDir = "prowlarr" # Note: Needs to be manually created on the share
}
secrets = {
"username" = "nomad"
"password" = data.sops_file.secrets.data["unraid.nomad"]
}
module "appdata_prowlarr" {
source = "./modules/appdata"
name = "prowlarr"
}

View File

@@ -26,53 +26,13 @@ resource "postgresql_database" "sonarr_log" {
owner = postgresql_role.sonarr.name
}
resource "nomad_csi_volume_registration" "unraid_appdata_sonarr" {
#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_sonarr"
name = "unraid_appdata_sonarr"
external_id = "unraid_appdata_sonarr"
capability {
access_mode = "single-node-writer"
attachment_mode = "file-system"
module "appdata_sonarr" {
source = "./modules/appdata"
name = "sonarr"
}
context = {
source = "//betelgeuse-seven-unraid.lan/appdata"
subDir = "sonarr" # Note: Needs to be manually created on the share
}
secrets = {
"username" = "nomad"
"password" = data.sops_file.secrets.data["unraid.nomad"]
}
}
resource "nomad_csi_volume_registration" "unraid_media_sonarr" {
#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_media_sonarr"
name = "unraid_media_sonarr"
external_id = "unraid_media_sonarr"
capability {
access_mode = "single-node-writer"
attachment_mode = "file-system"
}
context = {
source = "//betelgeuse-seven-unraid.lan/media"
}
secrets = {
"username" = "nomad"
"password" = data.sops_file.secrets.data["unraid.nomad"]
}
module "unraid_smb_sonarr_media" {
source = "./modules/unraid_smb"
name = "sonarr"
share = "media"
}

View File

@@ -2,53 +2,14 @@ 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"
module "unraid_smb_transfer" {
source = "./modules/unraid_smb"
name = "transfer"
id = "unraid_transfer"
share = "transfer"
}
context = {
source = "//betelgeuse-seven-unraid.lan/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 = "//betelgeuse-seven-unraid.lan/appdata"
subDir = "transferfilebrowser" # Note: Needs to be manually created on the share
}
secrets = {
"username" = "nomad"
"password" = data.sops_file.secrets.data["unraid.nomad"]
}
module "appdata_transferfilebrowser" {
source = "./modules/appdata"
name = "transferfilebrowser"
}

View File

@@ -3,30 +3,7 @@ resource "nomad_job" "unifi_network" {
jobspec = file("unifi.nomad.hcl")
}
resource "nomad_csi_volume_registration" "unraid_appdata_unifi_network" {
# Note: Before changing 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_unifi_network"
name = "unraid_appdata_unifi_network"
external_id = "unraid_appdata_unifi_network"
capability {
access_mode = "single-node-writer"
attachment_mode = "file-system"
module "appdata_unifi_network" {
source = "./modules/appdata"
name = "unifi-network"
}
context = {
source = "//betelgeuse-seven-unraid.lan/appdata"
subDir = "unifi-network" # Note: Needs to be manually created on the share
}
secrets = {
"username" = "nomad"
"password" = data.sops_file.secrets.data["unraid.nomad"]
}
}