67 lines
2.1 KiB
Terraform
67 lines
2.1 KiB
Terraform
locals {
|
|
access = merge(
|
|
{ for e in var.config.codeowners : e => "push" },
|
|
{ for e in var.config.maintainers : e => "maintain" },
|
|
)
|
|
}
|
|
|
|
resource "github_repository" "this" {
|
|
name = var.config.name
|
|
description = var.config.description
|
|
visibility = var.config.private ? "private" : "public"
|
|
has_issues = true
|
|
has_wiki = false
|
|
has_projects = false
|
|
allow_squash_merge = var.config.merge_type == "squash"
|
|
allow_merge_commit = var.config.merge_type == "merge"
|
|
allow_rebase_merge = var.config.merge_type == "rebase"
|
|
delete_branch_on_merge = var.config.delete_branch_on_merge
|
|
auto_init = true
|
|
archive_on_destroy = true
|
|
}
|
|
|
|
resource "github_branch_default" "this" {
|
|
repository = github_repository.this.name
|
|
branch = var.config.default_branch
|
|
# auto_init only creates main; rename it instead of pointing at a missing branch
|
|
rename = true
|
|
wait_for_rename = true
|
|
}
|
|
|
|
resource "github_repository_collaborators" "this" {
|
|
count = length(local.access) > 0 ? 1 : 0
|
|
|
|
repository = github_repository.this.name
|
|
|
|
dynamic "user" {
|
|
for_each = { for e, p in local.access : e => p if !startswith(e, "@") }
|
|
content {
|
|
username = user.key
|
|
permission = user.value
|
|
}
|
|
}
|
|
|
|
dynamic "team" {
|
|
for_each = { for e, p in local.access : trimprefix(e, "@") => p if startswith(e, "@") }
|
|
content {
|
|
team_id = var.team_slugs[team.key]
|
|
permission = team.value
|
|
}
|
|
}
|
|
}
|
|
|
|
resource "github_repository_file" "codeowners" {
|
|
count = length(var.config.maintainers) > 0 ? 1 : 0
|
|
|
|
repository = github_repository.this.name
|
|
branch = github_branch_default.this.branch
|
|
file = ".github/CODEOWNERS"
|
|
content = "* ${join(" ", [for e in var.config.maintainers : startswith(e, "@") ? "@${var.owner}/${var.team_slugs[trimprefix(e, "@")]}" : "@${e}"])}\n"
|
|
commit_message = "add initial CODEOWNERS"
|
|
overwrite_on_create = false
|
|
|
|
lifecycle {
|
|
ignore_changes = [content]
|
|
}
|
|
}
|