Skip to content

Commit

Permalink
Error catch (#27)
Browse files Browse the repository at this point in the history
* fix: update extra_files logic to handle empty ref cases and improve repository access safety

* fix: update default_branch output to use variable for new repositories

* fix: update ref logic to handle empty template repository cases and improve default branch output

---------

Co-authored-by: Dave Arnold <dave@roknsound.com>
  • Loading branch information
2 people authored and GitHub committed Apr 12, 2025
1 parent a5856ee commit 896c84a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion github_files.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ data "github_ref" "ref" {
count = local.lookup_sha
owner = var.template_repo_org
repository = var.template_repo
ref = "heads/${element(data.github_repository.template_repo, 0).default_branch}"
ref = "heads/${local.lookup_sha > 0 && length(data.github_repository.template_repo) > 0 ? coalesce(lookup(data.github_repository.template_repo[0], "default_branch", "main"), "main") : "main"}"
}

locals {
Expand Down
4 changes: 3 additions & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ output "visibility" {

output "default_branch" {
description = "Default branch of the repository"
value = var.create_repo ? var.github_default_branch : data.github_repository.existing[0].default_branch
value = var.create_repo ? var.github_default_branch : (
length(data.github_repository.existing) > 0 ? lookup(data.github_repository.existing[0], "default_branch", "main") : "main"
)
}

# resource "github_branch_default" "default_main_branch" {
Expand Down

0 comments on commit 896c84a

Please sign in to comment.