diff --git a/github_files.tf b/github_files.tf index 37aacbf..d9abe44 100644 --- a/github_files.tf +++ b/github_files.tf @@ -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 { diff --git a/outputs.tf b/outputs.tf index 2b04b55..d3ce572 100644 --- a/outputs.tf +++ b/outputs.tf @@ -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" {