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

resource "nomad_variable" "sonarr" {
  path = "nomad/jobs/sonarr"
  items = {
    database_pw = data.sops_file.secrets.data["sonarr.database_pw"]
  }
}

# https://wiki.servarr.com/sonarr/postgres-setup#schema-creation
resource "postgresql_role" "sonarr" {
  name     = "sonarr"
  password = data.sops_file.secrets.data["sonarr.database_pw"]
  login    = true
}

resource "postgresql_database" "sonarr_main" {
  name  = "sonarr-main"
  owner = postgresql_role.sonarr.name
}

resource "postgresql_database" "sonarr_log" {
  name  = "sonarr-log"
  owner = postgresql_role.sonarr.name
}

module "appdata_sonarr" {
  source = "./modules/appdata"
  name   = "sonarr"
}

module "unraid_smb_sonarr_media" {
  source = "./modules/unraid_smb"
  name   = "sonarr"
  share  = "media"
}
