From 722f8bc57b417f521c5437378fee95c036a700b5 Mon Sep 17 00:00:00 2001 From: David Arnold <10138997+djaboxx@users.noreply.github.com> Date: Sat, 12 Apr 2025 12:08:41 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20update=20extra=5Ffiles=20logic=20to=20ha?= =?UTF-8?q?ndle=20empty=20ref=20cases=20and=20improve=20r=E2=80=A6=20(#25)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: update extra_files logic to handle empty ref cases and improve repository access safety * terraform-docs: automated action --------- Co-authored-by: Dave Arnold Co-authored-by: github-actions[bot] --- README.md | 1 - github_files.tf | 4 ++-- github_repo.tf | 5 ++++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0a5d81b..c0e90cc 100644 --- a/README.md +++ b/README.md @@ -365,7 +365,6 @@ No modules. |------|-------------| | [default\_branch](#output\_default\_branch) | Default branch of the repository | | [full\_name](#output\_full\_name) | Full name of the repository in org/repo format | -| [generated\_deploy\_keys](#output\_generated\_deploy\_keys) | Generated private keys for deploy keys with create=true | | [git\_clone\_url](#output\_git\_clone\_url) | URL that can be provided to git clone to clone the repository anonymously via the git protocol | | [github\_repo](#output\_github\_repo) | All attributes of the GitHub repository | | [html\_url](#output\_html\_url) | URL to the repository on GitHub | diff --git a/github_files.tf b/github_files.tf index e526711..37aacbf 100644 --- a/github_files.tf +++ b/github_files.tf @@ -45,12 +45,12 @@ data "github_ref" "ref" { locals { extra_files = concat( var.extra_files, - local.lookup_sha == 1 && length(data.github_ref.ref) > 0 && length(data.github_ref.ref) == 0 ? [] : [ + local.lookup_sha == 1 ? [ { path = ".TEMPLATE_SHA", content = local.lookup_sha == 1 && length(data.github_ref.ref) > 0 ? data.github_ref.ref[0].sha : "" } - ] + ] : [] ) repository_name = var.create_repo ? local.github_repo.name : var.name } diff --git a/github_repo.tf b/github_repo.tf index 514adff..8243f9b 100644 --- a/github_repo.tf +++ b/github_repo.tf @@ -1,7 +1,10 @@ locals { repo_name = var.force_name ? var.name : "${var.name}-${formatdate("YYYYMMDD", timestamp())}" - github_repo = var.create_repo ? github_repository.repo[0] : data.github_repository.existing[0] + # Safe access to repo and existing resources + github_repo = var.create_repo && length(github_repository.repo) > 0 ? github_repository.repo[0] : ( + length(data.github_repository.existing) > 0 ? data.github_repository.existing[0] : null + ) validate_merge_options = ( var.github_allow_merge_commit ||