locals {
  # gets repo name in the first group (?P<repo>)
  # skips PR number and terraform workspace in the skipped (?:) group (for atlantis)
  # optional / for repositories where terraform configuration is located in the root
  # everything else goes to path group (?P<path>)
  repo_and_path               = regexall("/(?P<repo>terraform-[a-z-]+)(?:/[0-9]*/${terraform.workspace}/)?/?(?P<path>.*)", abspath(path.root))
  terraform_github_repository = local.repo_and_path[0].repo
  terraform_github_path       = local.repo_and_path[0].path
  service_name_map = var.service_name == "" ? {} : {
    service      = var.service_name
    service_name = var.service_name
  }

  # extract team names into a list for validation with datadog team handle
  valid_team_names = [for team in data.datadog_teams.pde.teams : team.handle]
  team             = var.team_name
}

data "datadog_teams" "pde" {
}
