variable "owner" { description = "GitHub organisation that owns every resource" type = string } variable "team" { description = "Map of teams to create, keyed by name" type = map(object({ name = string description = optional(string, "") privacy = optional(string, "closed") maintainers = optional(list(string), []) members = optional(list(string), []) })) default = {} } variable "ruleset" { description = "Map of reusable repository ruleset definitions, keyed by name" type = map(object({ name = string target = optional(string, "branch") enforcement = optional(string, "active") conditions = optional(object({ ref_name = object({ include = list(string) exclude = optional(list(string), []) }) })) rules = object({ deletion = optional(bool, false) non_fast_forward = optional(bool, false) pull_request = optional(object({ required_approving_review_count = optional(number, 0) dismiss_stale_reviews_on_push = optional(bool, false) require_code_owner_review = optional(bool, false) require_last_push_approval = optional(bool, false) required_review_thread_resolution = optional(bool, false) })) required_status_checks = optional(object({ contexts = list(string) strict = optional(bool, false) })) }) })) default = {} validation { condition = length(setintersection(keys(var.ruleset), ["branch-protection", "required-checks"])) == 0 error_message = "Ruleset names branch-protection and required-checks are reserved for generated rulesets." } } variable "repository" { description = "Map of repositories to create, keyed by name" type = map(object({ name = string description = optional(string, "") private = optional(bool, true) default_branch = optional(string, "main") maintainers = optional(list(string), []) codeowners = optional(list(string), []) merge_type = optional(string, "squash") delete_branch_on_merge = optional(bool, true) branch_protection = optional(bool) required_checks = optional(list(string), []) rulesets = optional(list(string), []) })) default = {} validation { condition = alltrue([for repo in var.repository : contains(["squash", "merge", "rebase"], repo.merge_type)]) error_message = "merge_type must be squash, merge or rebase: ${join(", ", [for name, repo in var.repository : name if !contains(["squash", "merge", "rebase"], repo.merge_type)])}." } validation { condition = alltrue([for repo in var.repository : !(repo.private && coalesce(repo.branch_protection, false))]) error_message = "branch_protection is not enforced on private repositories on the GitHub free plan: ${join(", ", [for name, repo in var.repository : name if repo.private && coalesce(repo.branch_protection, false)])}." } validation { condition = alltrue([for repo in var.repository : !(repo.private && length(repo.required_checks) > 0)]) error_message = "required_checks are not enforced on private repositories on the GitHub free plan: ${join(", ", [for name, repo in var.repository : name if repo.private && length(repo.required_checks) > 0])}." } validation { condition = alltrue([for repo in var.repository : !(repo.private && length(repo.rulesets) > 0)]) error_message = "rulesets are not enforced on private repositories on the GitHub free plan: ${join(", ", [for name, repo in var.repository : name if repo.private && length(repo.rulesets) > 0])}." } validation { condition = alltrue(flatten([for repo in var.repository : [for rs in repo.rulesets : contains(keys(var.ruleset), rs)]])) error_message = "Unknown rulesets referenced: ${join(", ", distinct(flatten([for name, repo in var.repository : [for rs in repo.rulesets : "${name}/${rs}" if !contains(keys(var.ruleset), rs)]])))}." } }