This repository has been archived on 2026-11-21. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
terraform-git/modules/github_org/variables.tf
T
unkin-agent 5a786be0e6
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/plan Pipeline was successful
Define all GitHub rulesets as ruleset/ files
2026-11-14 19:25:07 +11:00

142 lines
6.5 KiB
Terraform

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 repository ruleset definitions, keyed by name"
type = map(object({
name = string
all_repos = optional(bool, false)
mandatory = optional(bool, false)
target = optional(string, "branch")
enforcement = optional(string, "active")
conditions = optional(object({
ref_name = object({
include = list(string)
exclude = optional(list(string), [])
})
}))
rules = object({
creation = optional(bool, false)
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 = alltrue([for rs in var.ruleset : rs.target == "branch" || (rs.rules.pull_request == null && rs.rules.required_status_checks == null)])
error_message = "pull_request and required_status_checks are branch-only rules, not allowed on tag rulesets: ${join(", ", [for k, rs in var.ruleset : k if rs.target != "branch" && (rs.rules.pull_request != null || rs.rules.required_status_checks != null)])}."
}
validation {
condition = alltrue([for rs in var.ruleset : rs.rules.required_status_checks == null || length(rs.rules.required_status_checks.contexts) > 0])
error_message = "required_status_checks.contexts must not be empty: ${join(", ", [for k, rs in var.ruleset : k if rs.rules.required_status_checks != null && length(rs.rules.required_status_checks.contexts) == 0])}."
}
}
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)
rulesets = optional(list(string), [])
exclude_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 && 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 concat(repo.rulesets, repo.exclude_rulesets) : contains(keys(var.ruleset), rs)]]))
error_message = "Unknown rulesets referenced: ${join(", ", distinct(flatten([for name, repo in var.repository : [for rs in concat(repo.rulesets, repo.exclude_rulesets) : "${name}/${rs}" if !contains(keys(var.ruleset), rs)]])))}."
}
validation {
condition = alltrue(flatten([for repo in var.repository : [for rs in repo.exclude_rulesets : !try(var.ruleset[rs].mandatory, false)]]))
error_message = "Mandatory rulesets cannot be excluded: ${join(", ", flatten([for name, repo in var.repository : [for rs in repo.exclude_rulesets : "${name}/${rs}" if try(var.ruleset[rs].mandatory, false)]]))}."
}
validation {
condition = alltrue([for repo in var.repository : length(setintersection(repo.rulesets, repo.exclude_rulesets)) == 0])
error_message = "Rulesets both applied and excluded: ${join(", ", flatten([for name, repo in var.repository : [for rs in setintersection(repo.rulesets, repo.exclude_rulesets) : "${name}/${rs}"]]))}."
}
validation {
condition = alltrue(flatten([for repo in var.repository : [for e in concat(repo.maintainers, repo.codeowners) : contains(keys(var.team), trimprefix(e, "@")) if startswith(e, "@")]]))
error_message = "Unknown teams referenced: ${join(", ", distinct(flatten([for name, repo in var.repository : [for e in concat(repo.maintainers, repo.codeowners) : "${name}/${e}" if startswith(e, "@") && !contains(keys(var.team), trimprefix(e, "@"))]])))}."
}
}
variable "settings" {
description = "Organisation settings from config.yaml; null leaves them unmanaged"
type = object({
name = optional(string)
description = optional(string)
blog = optional(string)
location = optional(string)
email = optional(string)
twitter_username = optional(string)
company = optional(string)
default_repository_permission = optional(string, "read")
members_can_create_repositories = optional(bool, false)
public_runners = optional(bool, false)
})
default = null
validation {
condition = var.settings == null || contains(["read", "none"], try(var.settings.default_repository_permission, ""))
error_message = "default_repository_permission must be read or none."
}
}
variable "billing_email" {
description = "Organisation billing email, from TF_VAR_billing_email; required when settings is set"
type = string
default = null
sensitive = true
validation {
condition = var.settings == null || var.billing_email != null
error_message = "billing_email must be set when settings is set."
}
}