Manages GitHub repository settings and branch/tag protection for the
tailrocks organization: 46 repositories, each with repository merge
settings plus protect-main and protect-tags rulesets, and optional
per-repository tag-creation rulesets. Two exceptions: archived repositories
(archived = true) get no managed settings, because GitHub refuses changes to
them, and private repositories get no rulesets, because the free plan returns
403 for them.
variables.tf—repository_policiesinventory (single source of truth).locals.tf—check_templatescopy-paste source for check lists.repositories.tf—module.repository_policywiring.organization.tf— organization settings, Actions/workflow permissions, and thevelnor-trustedrunner group.modules/repository-policy/— shared policy module (identical across orgs).checks.tf— invariant guards (no scripts).imports.tf— bootstrap import triples (one per repo: settings + 2 rulesets).providers.tf,versions.tf,outputs.tf— provider, pins, outputs.
Run tofu with GITHUB_TOKEN exported in the shell, or via the mise tasks
mise run tofu:plan / mise run tofu:apply, which inject the organization
token from 1Password. The token needs Administration: write on every managed
repository. It also needs org admin on tailrocks for the organization
settings, Actions policies, and runner group in organization.tf.
- Add one entry to
repository_policiesinvariables.tf, copying a check list fromlocals.tf(dco_policy_ci=["DCO", "Policy", "ci-required"],dco_required=["DCO", "Required"],control=["Control / Required"],required_only=["Required"],dco_only=["DCO"],policy=["Policy"]); bespoke checks inline with a comment citing the producing workflow. Repos with no CI userequired_checks = []plus a non-emptyno_ci_reasonand extend the allowlist check inchecks.tf. Always add the name to the mandatory list inmandatory_target_repositories_presentinchecks.tf(updating its count and message). - Add one import triple (settings +
protect_main+protect_tags) toimports.tfusing the live numeric ruleset IDs. A private repository gets only the settings import; an archived one gets only the two ruleset imports.
Each repository_policies entry may also set:
archived(defaultfalse): set it for a repository that is archived on GitHub. The module then skips its settings and reads its ID through a data source; its rulesets stay managed.strict_required_status_checks(defaultfalse): require the branch to be up to date with the default branch before merging.protect_tags_update(defaultfalse): add theupdaterule toprotect-tags, so that existing tags cannot move.tag_creation_rulesets(default{}): extra tag rulesets, keyed by ruleset name, with thecreationrule for theincludepatterns and analwaysbypass for each user inbypass_user_ids. Import each existing ruleset astag_creation["<repository>/<ruleset name>"]inimports.tf.
organization.tfmanages the org profile (github_organization_settings), Actions availability/allow policy (github_actions_organization_permissions), defaultGITHUB_TOKENworkflow permissions (github_actions_organization_workflow_permissions), and thevelnor-trustedrunner group restricted tovar.velnor_runner_group_repositories(must be a subset ofrepository_policies).- GitHub does not expose organization package-creation visibility through the REST API or the Terraform GitHub provider; manage those settings in Organization settings → Packages. Making a package public is irreversible.
tofu fmt -check -recursive
tofu init -backend=false -input=false -lockfile=readonly
tofu validate -no-colorOpenTofu is pinned via mise.toml (opentofu 1.13.1); existing repos are
imported via imports.tf on first apply.