# delphi-data-health
resource "jenkins_folder" "delphi_data_health" {
  name   = "delphi-data-health"
  folder = data.jenkins_folder.delphi_monorepos.id
}

resource "jenkins_folder" "delphi_data_health_lambdas" {
  name   = "lambdas"
  folder = jenkins_folder.delphi_data_health.id
}

resource "jenkins_folder" "delphi_data_health_liquibase" {
  name   = "liquibase"
  folder = jenkins_folder.delphi_data_health.id
}

locals {
  delphi_data_health_git_name     = "delphi-data-health"
  delphi_data_health_git_http_url = "https://github.com/theorchard/delphi-data-health.git"
  delphi_data_health_git_ssh_url  = "git@github.com:theorchard/delphi-data-health.git"
  delphi_data_health_jobs = {
    dh_data_health_agent = {
      name             = "dh_data_health_agent"
      folder           = jenkins_folder.delphi_data_health_lambdas.id
      disabled         = false
      jenkinsfile_path = "src/dh_data_health_agent/Jenkinsfile"
    },
    data_health_schema = {
      name             = "data_health_schema"
      folder           = jenkins_folder.delphi_data_health_liquibase.id
      disabled         = false
      jenkinsfile_path = "liquibase/data_health_schema/Jenkinsfile"
    },
    data-health-pipeline-manager = {
      name              = "data-health-pipeline-manager"
      folder            = jenkins_folder.delphi_data_health.id
      branches_to_build = ["develop", "release", "hotfix"]
      jenkins_job_type  = "manager"
      disabled          = false
      jenkinsfile_path  = "Jenkinsfile"
    }
  }
}

module "delphi_data_health" {
  for_each = local.delphi_data_health_jobs

  source = "../../modules/jenkins/multibranch-pipeline-delphi-monorepos"

  disabled = each.value["disabled"]
  folder   = each.value["folder"]

  github_repository_name              = local.delphi_data_health_git_name
  github_repository_http_url          = local.delphi_data_health_git_http_url
  github_repository_ssh_url           = local.delphi_data_health_git_ssh_url
  github_repository_branches_to_build = lookup(each.value, "branches_to_build", [])
  jenkinsfile_path                    = each.value["jenkinsfile_path"]
  jenkins_job_type                    = lookup(each.value, "jenkins_job_type", "project")
  jenkins_job_name                    = each.value["name"]

  github_ssh_credentials_id = "theorchard-ci-ssh-key"
  github_credentials_id     = "orchardci-user-token"
  github_repository_owner   = "theorchard"
}
