Support non-main default branch via the branches map (+ demotion guard) - #81
Merged
Merged
Conversation
This reverts commit a0a6784.
Reimplements non-main default branch support (previously #57's provider `rename`, reverted in the prior commit) by injecting the desired default branch into the module's branches map so it is created as a real github_branch resource, then pointed at by github_branch_default. - vendored module: when default_branch is non-main (and auto_init is set, and it is not already listed in var.branches), append it to branches_map so github_branch creates it off the auto-init "main". - root module: add an import block for github_branch.branch[default_branch] scoped to generated_repos with a non-main default, so existing repos import the branch instead of failing to create one that already exists.
Switching a repository's default branch from a non-main branch (e.g. master) back to main cannot be applied directly: Terraform destroys the managed github_branch before demoting the default, and GitHub rejects deleting a repository's default branch (422). The plan succeeds but the apply fails and keeps failing until state is reconciled. - docs/switching-default-branch-to-main.md: runbook — state rm the branch first (forgets it without deleting), then flip the YAML to main. - tf-plan.yaml (Report result): detect a github_branch.branch deletion in the plan summary, prepend a warning linking the runbook to the PR comment, and set the check run to action_required so a required check blocks the merge until the runbook is followed. Self-clears once the branch is state-rm'd.
dev-milos
approved these changes
Sep 23, 2026
Collaborator
|
LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lets a repo's default branch (e.g.
master) be set declaratively from YAML, including on existing repos — replacing #57'srename(reverted here), which was create-only and forced hand-creating the branch + a PR for existing repos.Changes
maindefault_branchintobranches_mapsogithub_branchcreates it off the auto-initmain, thengithub_branch_defaultpoints at it.import {}block for the default branch (scoped toimporter_tmp_dir/) so existing repos import it instead of colliding.master → main, which otherwise fails apply with422 Cannot delete the default branch): runbookdocs/switching-default-branch-to-main.md(state rmthe branch first), and a tf-plan check that warns + sets the checkaction_requiredto block merge until the runbook is followed.Rollout note: on a workspace with existing non-
main-default repos, import their default branches into state first, or the first apply fails (422/404).Verified end-to-end on the dev workspace (all creation paths + a real demotion PR).