Skip to content

Commit

Permalink
Refactor repository references to use local.github_repo for consisten…
Browse files Browse the repository at this point in the history
…cy and improve dependency management in branch protection and GitHub files
  • Loading branch information
Dave Arnold committed Feb 19, 2025
1 parent d0c2036 commit a0ae631
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
4 changes: 0 additions & 4 deletions action_secrets.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
locals {
repo_exists = var.create_repo ? github_repository.repo[0] : data.github_repository.existing[0]
}

resource "github_actions_secret" "secret" {
for_each = tomap({ for secret in var.secrets : secret.name => secret.value })
repository = local.github_repo.name
Expand Down
4 changes: 2 additions & 2 deletions branch_protection.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ locals {
resource "github_branch_protection" "protection" {
for_each = local.branch_protection_rules

repository_id = local.repo_exists.node_id
repository_id = local.github_repo.id
pattern = each.value.pattern
enforce_admins = each.value.enforce_admins
allows_deletions = try(each.value.allows_deletions, false)
Expand Down Expand Up @@ -48,7 +48,7 @@ resource "github_branch_protection" "protection" {
}

depends_on = [
local.repo_exists,
github_repository.repo,
github_repository_file.codeowners,
github_repository_file.extra_files,
github_repository_file.managed_extra_files
Expand Down
4 changes: 2 additions & 2 deletions github_branch.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ locals {

# https://registry.terraform.io/providers/integrations/github/latest/docs/resources/branch_protection
resource "github_branch_protection" "main" {
count = var.create_repo && (var.enforce_prs && !var.github_is_private) || var.github_is_private ? 1 : 0
count = (var.enforce_prs && !var.github_is_private) || var.github_is_private ? 1 : 0

repository_id = github_repository.repo[0].node_id
repository_id = local.github_repo.id
pattern = var.github_default_branch
enforce_admins = var.github_enforce_admins_branch_protection
allows_deletions = false
Expand Down
6 changes: 3 additions & 3 deletions github_files.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ resource "github_repository_file" "codeowners" {
commit_author = var.commit_author
commit_email = var.commit_email
overwrite_on_create = true
depends_on = [local.repo_exists]
depends_on = [github_repository.repo]
lifecycle {
ignore_changes = [
content,
Expand Down Expand Up @@ -60,7 +60,7 @@ resource "github_repository_file" "extra_files" {
commit_author = var.commit_author
commit_email = var.commit_email
overwrite_on_create = true
depends_on = [local.repo_exists]
depends_on = [github_repository.repo]
lifecycle {
ignore_changes = [
content,
Expand All @@ -80,7 +80,7 @@ resource "github_repository_file" "managed_extra_files" {
commit_author = var.commit_author
commit_email = var.commit_email
overwrite_on_create = true
depends_on = [local.repo_exists]
depends_on = [github_repository.repo]
lifecycle {
ignore_changes = [
branch
Expand Down

0 comments on commit a0ae631

Please sign in to comment.