# Terraform backends cannot contain interpolations
terraform {
  backend "s3" {
    bucket  = "orcd-terraform-state"
    key     = "prod/github/atlas-expo-integration-example/terraform.tfstate"
    region  = "us-east-1"
    encrypt = "true"
  }
}

module "github_repositories" {
  source = "git@github.com:theorchard/terraform-github.git//?ref=2.1.4"
  github_repository_names = {
    atlas-expo-integration-example = {
      branch_protection_enabled        = true
      branch_protection_enforce_admins = true
      repo_auto_init                   = false
      archived_repository              = false
      github_code_owner_reviews        = true
      visibility                       = "private"
      description                      = "Atlas to Expo integration example (Managed by Terraform)"
      has_downloads                    = false
      homepage_url                     = ""
    }
  }

  github_pull_teams = ["atlas-team"]
  github_push_teams = ["mergers", "atlas-be-team", "atlas-fe-team"]

  branch_protection_required_status_checks = true
  github_code_owner_reviews                = true

  allow_merge_commit = true
}

resource "github_branch_protection" "branch_develop_protection" {
  # checkov:skip=CKV_GIT_5:We required only one reviewer in the established workflow.
  # checkov:skip=CKV_GIT_6:We don't require Git commits to be GPG signed.

  repository_id  = module.github_repositories.github_repository_node_id["atlas-expo-integration-example"]
  pattern        = "develop"
  enforce_admins = true

  required_status_checks {
    strict = true
  }

  required_pull_request_reviews {
    dismiss_stale_reviews      = true
    require_code_owner_reviews = true
  }
}
