diff --git a/.github/workflows/apply.yml b/.github/workflows/apply.yml index 97d8807..957b8e1 100644 --- a/.github/workflows/apply.yml +++ b/.github/workflows/apply.yml @@ -6,6 +6,7 @@ on: - main paths: - 'terraform/production/*.tfvars' + - 'terraform/*.tf' concurrency: group: terraform-actions diff --git a/.github/workflows/plan.yml b/.github/workflows/plan.yml index 916f3dc..f8abaf6 100644 --- a/.github/workflows/plan.yml +++ b/.github/workflows/plan.yml @@ -5,6 +5,7 @@ on: - main paths: - 'terraform/production/*.tfvars' + - 'terraform/*.tf' concurrency: group: terraform-actions diff --git a/terraform/README.md b/terraform/README.md index 8097372..165b7dd 100644 --- a/terraform/README.md +++ b/terraform/README.md @@ -51,7 +51,6 @@ All changes should be made in `production/*.tfvars`: topics = [] visibility = "public" # optional, default is "public" is_django_commons_repo = optional(bool, false) # Do not create teams for repository - enable_branch_protection = true # optional, default is true required_status_checks_contexts = [] # optional, default is [] admins = [] # Members of the repository's admin and repository teams. Have admin permissions committers = [] # Members of the repository's committers and repository teams. Have write permissions diff --git a/terraform/locals.tf b/terraform/locals.tf index ed45cae..420824d 100644 --- a/terraform/locals.tf +++ b/terraform/locals.tf @@ -3,21 +3,6 @@ locals { - admins = { - for user in var.admins : user => "admin" - } - - branch_protections = { - for repository_key, repository in var.repositories : repository_key => repository - if repository.enable_branch_protection - } - - members = { - for user in var.members : user => "member" - } - - users = merge(local.admins, local.members) - project_repositories = { for repository_key, repository in var.repositories : repository_key => repository if !repository.is_django_commons_repo diff --git a/terraform/production/repositories.tfvars b/terraform/production/repositories.tfvars index f601044..5e67cde 100644 --- a/terraform/production/repositories.tfvars +++ b/terraform/production/repositories.tfvars @@ -2,8 +2,7 @@ repositories = { ".github" = { - description = "A Special Repository." - enable_branch_protection = false + description = "A Special Repository." topics = [] push_allowances = [] @@ -11,14 +10,13 @@ repositories = { } "controls" = { - description = "The controls for managing Django Commons projects" - enable_branch_protection = false - allow_merge_commit = true - allow_rebase_merge = true - allow_squash_merge = true - topics = [] - push_allowances = [] - is_django_commons_repo = true + description = "The controls for managing Django Commons projects" + allow_merge_commit = true + allow_rebase_merge = true + allow_squash_merge = true + topics = [] + push_allowances = [] + is_django_commons_repo = true } "membership" = { @@ -162,7 +160,6 @@ repositories = { "tailwindcss", ] visibility = "public" - enable_branch_protection = true required_status_checks_contexts = [] admins = [ "oliverandrich", diff --git a/terraform/resources-org.tf b/terraform/resources-org.tf index 4367822..3022e2d 100644 --- a/terraform/resources-org.tf +++ b/terraform/resources-org.tf @@ -1,5 +1,19 @@ # GitHub Membership Resource # https://registry.terraform.io/providers/integrations/github/latest/docs/resources/membership +data "github_users" "users" { + usernames = setunion(var.admins, var.members) +} + +output "invalid_users" { + value = data.github_users.users.unknown_logins +} + +locals { + users = merge( + { for user in var.admins : user => "admin" if contains(data.github_users.users.logins, user) }, + { for user in var.members : user => "member" if contains(data.github_users.users.logins, user) } + ) +} resource "github_membership" "this" { for_each = local.users diff --git a/terraform/variables.tf b/terraform/variables.tf index 86a972a..99a37ec 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -33,7 +33,6 @@ variable "repositories" { homepage_url = optional(string, "") has_wiki = optional(bool, false) push_allowances = optional(list(string), []) - enable_branch_protection = optional(bool, true) required_status_checks_contexts = optional(list(string), []) is_template = optional(bool, false) # Is the repository a template repository topics = optional(list(string))