
resource "nomad_job" "immich" {
  jobspec = file("immich.nomad.hcl")
}

resource "postgresql_role" "immich" {
  name     = "immich"
  password = data.sops_file.secrets.data["immich.database_pw"]
  login    = true
}

resource "postgresql_database" "immich" {
  name  = "immich"
  owner = postgresql_role.immich.name
}

resource "postgresql_extension" "immich_vchord" {
  name           = "vchord"
  database       = postgresql_database.immich.name
  create_cascade = true
}

resource "postgresql_extension" "immich_earthdistance" {
  name           = "earthdistance"
  database       = postgresql_database.immich.name
  create_cascade = true
}

resource "nomad_variable" "immich" {
  path = "nomad/jobs/immich"
  items = {
    database_pw           = data.sops_file.secrets.data["immich.database_pw"]
    tailscale_oauthsecret = data.sops_file.secrets.data["tailscale.oauthsecret"]
  }
}

module "appdata_immich" {
  source = "./modules/appdata"
  name   = "immich"
}

module "unraid_smb_immich_photosvideos" {
  source = "./modules/unraid_smb"
  name   = "photosvideos"
  share  = "media"
  subDir = "Photos and Videos"
}

module "unraid_smb_immich_encodedvideo" {
  source = "./modules/unraid_smb"
  name   = "immich_encodedvideo"
  share  = "media"
  subDir = "immich/encoded-video"
}

module "unraid_smb_immich_mediadump_photosvideos" {
  source = "./modules/unraid_smb"
  name   = "photosvideos"
  id     = "unraid_mediadump_photosvideos"
  share  = "media-dump"
  subDir = "Photos and Videos"
}
