Skip to content

Commit

Permalink
fix: update extra_files logic to handle empty ref cases and improve r…
Browse files Browse the repository at this point in the history
…… (#25)

* fix: update extra_files logic to handle empty ref cases and improve repository access safety

* terraform-docs: automated action

---------

Co-authored-by: Dave Arnold <dave@roknsound.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored and GitHub committed Apr 12, 2025
1 parent b6b6cba commit 722f8bc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ No modules.
|------|-------------|
| <a name="output_default_branch"></a> [default\_branch](#output\_default\_branch) | Default branch of the repository |
| <a name="output_full_name"></a> [full\_name](#output\_full\_name) | Full name of the repository in org/repo format |
| <a name="output_generated_deploy_keys"></a> [generated\_deploy\_keys](#output\_generated\_deploy\_keys) | Generated private keys for deploy keys with create=true |
| <a name="output_git_clone_url"></a> [git\_clone\_url](#output\_git\_clone\_url) | URL that can be provided to git clone to clone the repository anonymously via the git protocol |
| <a name="output_github_repo"></a> [github\_repo](#output\_github\_repo) | All attributes of the GitHub repository |
| <a name="output_html_url"></a> [html\_url](#output\_html\_url) | URL to the repository on GitHub |
Expand Down
4 changes: 2 additions & 2 deletions github_files.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 4 additions & 1 deletion github_repo.tf
Original file line number Diff line number Diff line change
@@ -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 ||
Expand Down

0 comments on commit 722f8bc

Please sign in to comment.