Skip to content

Commit

Permalink
feat: add files_branch variable and improve branch management logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Jun 30, 2025
1 parent 6140ffe commit 4f1e581
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion branch_protection.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ locals {
# https://registry.terraform.io/providers/integrations/github/latest/docs/resources/branch_protection
resource "github_branch_protection" "protection" {
for_each = {
for k, v in local.branch_protection_rules : k => v if var.enforce_prs && (!var.github_is_private || var.github_pro_enabled)
for k, v in local.branch_protection_rules : k => v if var.enforce_prs && (! var.github_is_private || var.github_pro_enabled)
}

repository_id = var.create_repo ? github_repository.repo[0].node_id : data.github_repository.existing[0].node_id
Expand Down
6 changes: 3 additions & 3 deletions github_files.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
locals {
# Process files only if commit signing is not required or if explicitly allowed
should_manage_files = !try(local.github_repo.require_signed_commits, false) || var.allow_unsigned_files
should_manage_files = ! try(local.github_repo.require_signed_commits, false) || var.allow_unsigned_files
}

# https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_file
Expand Down Expand Up @@ -59,7 +59,7 @@ resource "github_repository_file" "extra_files" {
for_each = local.should_manage_files ? tomap({ for file in local.extra_files : "${element(split("/", file.path), length(split("/", file.path)) - 1)}" => file }) : {}

repository = local.github_repo.name
branch = var.github_default_branch
branch = var.files_branch == null ? var.github_default_branch : var.files_branch
file = each.value.path
content = each.value.content
commit_message = "Update ${each.value.path}"
Expand All @@ -81,7 +81,7 @@ resource "github_repository_file" "managed_extra_files" {
for_each = local.should_manage_files ? tomap({ for file in var.managed_extra_files : "${element(split("/", file.path), length(split("/", file.path)) - 1)}" => file }) : {}

repository = local.github_repo.name
branch = var.github_default_branch
branch = var.files_branch == null ? var.github_default_branch : var.files_branch
file = each.value.path
content = each.value.content
commit_message = "Update ${each.value.path}"
Expand Down
7 changes: 7 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ variable "github_default_branch" {
type = string
default = "main"
}

variable "files_branch" {
description = "Branch to manage files on"
type = string
default = null
}

variable "github_required_approving_review_count" {
description = "Number of approvals needed for pull requests"
type = number
Expand Down

0 comments on commit 4f1e581

Please sign in to comment.