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

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

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

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

module "appdata_openreader" {
  source = "./modules/appdata"
  name   = "openreader"
}
