diff --git a/github_branch.tf b/github_branch.tf index 57ccf01..2240fc7 100644 --- a/github_branch.tf +++ b/github_branch.tf @@ -24,15 +24,22 @@ resource "github_branch_default" "default_main_branch" { ] } -# For new repos: create files_branch inside the module after repo exists. -# For existing repos: files_branch is created externally (in terraform-eks-deployment) before the module runs. +# Create files_branch for both new repos (create_repo=true) and existing repos (create_repo=false). +# source_branch can be customized via files_branch_source_branch; defaults to the repo default branch. resource "github_branch" "files_branch" { - count = var.files_branch != null && var.create_repo ? 1 : 0 - repository = local.repo_name + count = var.files_branch != null ? 1 : 0 + repository = local.repository_name branch = var.files_branch - source_branch = var.github_default_branch + source_branch = coalesce(var.files_branch_source_branch, var.github_default_branch) - depends_on = [github_repository.repo] + depends_on = [ + github_repository.repo, + data.github_repository.existing, + ] + + lifecycle { + ignore_changes = [source_branch, source_sha] + } } data "github_user" "pull_request_bypassers" { diff --git a/variables.tf b/variables.tf index e915fbf..7b38937 100644 --- a/variables.tf +++ b/variables.tf @@ -87,6 +87,12 @@ variable "files_branch" { default = null } +variable "files_branch_source_branch" { + description = "Source branch to create files_branch from. If null, the repository default branch is used. Only has effect when files_branch is set." + type = string + default = null +} + variable "github_required_approving_review_count" { description = "Number of approvals needed for pull requests" type = number