Skip to content

Commit

Permalink
adding .TEMPLATE_SHA
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Arnold committed Jul 9, 2024
1 parent 9bc4313 commit e55c1e5
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion github_files.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,3 +53,5 @@ resource "github_repository_file" "extra_files" {
]
}
}


0 comments on commit e55c1e5

Please sign in to comment.