Skip to content

Commit

Permalink
dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Jan 22, 2024
1 parent c48815d commit bc4209b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
20 changes: 0 additions & 20 deletions terraform/modules/github_repository/branch.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
21 changes: 21 additions & 0 deletions terraform/modules/github_repository/repository.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
6 changes: 6 additions & 0 deletions terraform/modules/github_repository/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit bc4209b

Please sign in to comment.