From e55c1e5d4d2b18068bb559d05052a0618c058a27 Mon Sep 17 00:00:00 2001 From: Dave Arnold Date: Mon, 8 Jul 2024 21:14:24 -0700 Subject: [PATCH] adding .TEMPLATE_SHA --- github_files.tf | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/github_files.tf b/github_files.tf index ca280c4..f9abb76 100644 --- a/github_files.tf +++ b/github_files.tf @@ -14,8 +14,33 @@ resource "github_repository_file" "codeowners" { } } + +data "github_repository" "template_repo" { + count = var.template_repo == null ? 0 : 1 + full_name = "${var.template_repo_org}/${var.template_repo}" +} + +data "github_ref" "ref" { + count = var.template_repo == null ? 0 : 1 + owner = var.template_repo_org + repository = var.template_repo + ref = "heads/${element(data.github_repository.template_repo, 0).default_branch}" +} + +locals { + extra_files = concat( + var.extra_files, + var.template_repo == null ? [] : [ + { + path = ".TEMPLATE_SHA", + content = data.github_ref.ref[0].sha + } + ] + ) +} + resource "github_repository_file" "extra_files" { - for_each = tomap({ for file in var.extra_files : "${element(split("/", file.path), length(split("/", file.path)) - 1)}" => file }) + for_each = tomap({ for file in local.extra_files : "${element(split("/", file.path), length(split("/", file.path)) - 1)}" => file }) repository = github_repository.repo.name branch = var.github_default_branch file = each.value.path @@ -28,3 +53,5 @@ resource "github_repository_file" "extra_files" { ] } } + +