From 4cf809e6c23c312e1c8fb10473e8808fb05e9afb Mon Sep 17 00:00:00 2001 From: Dave Arnold Date: Fri, 21 Feb 2025 12:00:26 -0800 Subject: [PATCH] Refactor branch creation and default setting logic to eliminate unnecessary preconditions --- github_branch.tf | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/github_branch.tf b/github_branch.tf index 82a6b26..df50f20 100644 --- a/github_branch.tf +++ b/github_branch.tf @@ -5,17 +5,9 @@ # Create non-main default branch if specified resource "github_branch" "branch" { + count = var.github_default_branch != "main" ? 1 : 0 repository = local.github_repo.name branch = var.github_default_branch - - # Only create if not "main" and repository exists - lifecycle { - precondition { - condition = var.github_default_branch != "main" - error_message = "Default branch is 'main', skipping branch creation as it's created by default" - } - } - depends_on = [ github_repository.repo ] @@ -23,17 +15,9 @@ resource "github_branch" "branch" { # Set the default branch resource "github_branch_default" "default_main_branch" { + count = var.github_default_branch != "main" ? 1 : 0 repository = local.github_repo.name branch = var.github_default_branch - - # Only set if not "main" - lifecycle { - precondition { - condition = var.github_default_branch != "main" - error_message = "Default branch is already 'main', no need to set default" - } - } - depends_on = [ github_branch.branch ]