diff --git a/terraform/modules/github_repository/branch.tf b/terraform/modules/github_repository/branch.tf index 700c11d77..f1f886cd0 100644 --- a/terraform/modules/github_repository/branch.tf +++ b/terraform/modules/github_repository/branch.tf @@ -27,23 +27,3 @@ resource "github_branch_protection" "main" { required_approving_review_count = 0 } } - - -resource "github_branch_protection" "next-release" { - # Branch protection can only be enabled on private repositories if using a - # paid GitHub plan - count = var.visibility == "public" ? 1 : 0 - - repository_id = github_repository.repository.node_id - pattern = "next-*" - enforce_admins = true - required_linear_history = false - allows_deletions = false - allows_force_pushes = true - blocks_creations = false - - required_status_checks { - strict = true - contexts = null - } -} diff --git a/terraform/modules/github_repository/repository.tf b/terraform/modules/github_repository/repository.tf index 98e18c1db..716194df8 100644 --- a/terraform/modules/github_repository/repository.tf +++ b/terraform/modules/github_repository/repository.tf @@ -36,4 +36,25 @@ resource "github_repository" "repository" { } } } + + dynamic "github_branch_protection" { + for_each = var.has_release_branches ? [1] : [] + + content { + count = var.visibility == "public" ? 1 : 0 + + repository_id = github_repository.repository.node_id + pattern = "next-*" + enforce_admins = true + required_linear_history = false + allows_deletions = false + allows_force_pushes = true + blocks_creations = false + + required_status_checks { + strict = true + contexts = null + } + } + } } diff --git a/terraform/modules/github_repository/variables.tf b/terraform/modules/github_repository/variables.tf index d02124783..0b7aee264 100644 --- a/terraform/modules/github_repository/variables.tf +++ b/terraform/modules/github_repository/variables.tf @@ -109,6 +109,12 @@ variable "default_branch" { default = "main" } +variable "has_release_branches" { + type = bool + description = "Has next-* branches for releases" + default = false +} + variable "allow_merge_commit" { type = bool description = "Set to 'false' to disable merge commits to be created within the repository."