From 4f1e581dd5827a644515cd02edb84826faad24f3 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 30 Jun 2025 14:17:54 -0400 Subject: [PATCH] feat: add files_branch variable and improve branch management logic --- branch_protection.tf | 2 +- github_files.tf | 6 +++--- variables.tf | 7 +++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/branch_protection.tf b/branch_protection.tf index c8e4ef4..c751f53 100644 --- a/branch_protection.tf +++ b/branch_protection.tf @@ -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 diff --git a/github_files.tf b/github_files.tf index d9abe44..cafffac 100644 --- a/github_files.tf +++ b/github_files.tf @@ -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 @@ -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}" @@ -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}" diff --git a/variables.tf b/variables.tf index d2edf91..e02e81e 100644 --- a/variables.tf +++ b/variables.tf @@ -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