diff --git a/modules/github_org/main.tf b/modules/github_org/main.tf index 3229fb0..293d971 100644 --- a/modules/github_org/main.tf +++ b/modules/github_org/main.tf @@ -50,6 +50,7 @@ resource "github_repository" "this" { allow_rebase_merge = each.value.allow_rebase_merge delete_branch_on_merge = each.value.delete_branch_on_merge auto_init = each.value.auto_init + archive_on_destroy = true } resource "github_branch_default" "this" { diff --git a/modules/github_org/tests/github_org.tftest.hcl b/modules/github_org/tests/github_org.tftest.hcl index 62bdcde..3c5e53b 100644 --- a/modules/github_org/tests/github_org.tftest.hcl +++ b/modules/github_org/tests/github_org.tftest.hcl @@ -65,3 +65,15 @@ run "private_repo_with_ruleset_rejected" { expect_failures = [var.repository] } + +run "unknown_ruleset_rejected" { + command = plan + + variables { + repository = { + public = { name = "public", private = false, rulesets = ["missing"] } + } + } + + expect_failures = [var.repository] +} diff --git a/modules/github_org/variables.tf b/modules/github_org/variables.tf index d061682..e79ef15 100644 --- a/modules/github_org/variables.tf +++ b/modules/github_org/variables.tf @@ -71,4 +71,9 @@ variable "repository" { condition = alltrue([for repo in var.repository : !(repo.private && length(repo.rulesets) > 0)]) error_message = "Rulesets are not enforced on private repositories on the GitHub free plan: ${join(", ", [for name, repo in var.repository : name if repo.private && length(repo.rulesets) > 0])}." } + + validation { + condition = alltrue(flatten([for repo in var.repository : [for rs in repo.rulesets : contains(keys(var.ruleset), rs)]])) + error_message = "Unknown rulesets referenced: ${join(", ", distinct(flatten([for name, repo in var.repository : [for rs in repo.rulesets : "${name}/${rs}" if !contains(keys(var.ruleset), rs)]])))}." + } }