Skip to content

Commit

Permalink
Refactor branch creation and default setting logic to eliminate unnec…
Browse files Browse the repository at this point in the history
…essary preconditions
  • Loading branch information
Dave Arnold committed Feb 21, 2025
1 parent aed1d23 commit 4cf809e
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions github_branch.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,19 @@

# 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
]
}

# 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
]
Expand Down

0 comments on commit 4cf809e

Please sign in to comment.