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

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

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

resource "postgresql_database" "prowlarr_main" {
  name  = "prowlarr-main"
  owner = postgresql_role.prowlarr.name
}

resource "postgresql_database" "prowlarr_log" {
  name  = "prowlarr-log"
  owner = postgresql_role.prowlarr.name
}

module "appdata_prowlarr" {
  source = "./modules/appdata"
  name   = "prowlarr"
}
