module "atlas_job" {
  for_each = local.atlas_jobs

  source = "../../modules/jenkins/multibranch-pipeline-remote-jenkinsfile"

  disabled = each.value["disabled"]

  folder = jenkins_folder.atlas_pipelines.id

  github_repository_http_url          = each.value["http_url"]
  github_repository_name              = each.value["name"]
  github_repository_ssh_url           = each.value["ssh_url"]
  github_repository_branches_to_build = each.value["branches_to_build"]
  jenkinsfile_branch                  = lookup(each.value, "jenkinsfile_branch", "develop")
  jenkinsfile_path                    = lookup(each.value, "jenkinsfile_path", "Jenkinsfile")

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

module "atlas_schedule" {
  for_each = local.atlas_schedule_jobs

  source = "../../modules/jenkins/scheduled-pipeline"

  disabled = each.value["disabled"]

  folder = jenkins_folder.atlas_schedule.id

  jenkins_job_name          = lookup(each.value, "job_name", each.value["repository_name"])
  github_repository_name    = each.value["repository_name"]
  github_repository_ssh_url = each.value["ssh_url"]

  jenkinsfile_branch  = lookup(each.value, "jenkinsfile_branch", "master")
  jenkinsfile_path    = each.value["jenkinsfile_path"]
  schedule_expression = each.value["schedule_expression"]
}
