-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgh-protections.tf
More file actions
83 lines (79 loc) · 3.2 KB
/
Copy pathgh-protections.tf
File metadata and controls
83 lines (79 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Resolve the chart updater App to its GraphQL node ID. Branch protection
# allowances cannot use the App's numeric ID or bot login directly.
data "github_app" "chart_updater" {
slug = "makeitworkbot"
}
# Strict protection requires pull requests and configured CI checks. Private
# repositories remain excluded because their GitHub plan does not enforce this
# organization policy through this resource.
resource "github_branch_protection" "protections" {
for_each = {
for name, repository in local.repositories : name => repository
if !repository.archived && !repository.private && repository.protection_profile == "strict"
}
repository_id = github_repository.repositories[each.key].node_id
pattern = "main"
enforce_admins = true
allows_force_pushes = false
required_linear_history = true
require_conversation_resolution = true
required_status_checks {
strict = true
contexts = each.value.required_status_checks
}
# This block requires a pull request while retaining the solo-maintainer
# workflow: zero approvals, no code-owner gate, and no bypass actors.
required_pull_request_reviews {
require_code_owner_reviews = false
required_approving_review_count = 0
require_last_push_approval = false
}
restrict_pushes {
# Push allowances do not bypass the pull-request or required-check gates.
# The chart updater App is added only for its kustomize-cluster destination
# so GitHub may complete an eligible auto-merge after `test` passes.
push_allowances = concat(
["${var.github_owner}/${github_team.admins.slug}"],
each.key == "kustomize-cluster" ? [data.github_app.chart_updater.node_id] : [],
)
}
# Seed centrally managed files before protecting a newly added repository's
# main branch. Without this ordering, GitHub can reject the file commits as
# soon as the required-check rule is created in the same apply.
depends_on = [
github_repository.repositories,
github_repository_file.dependabot,
github_repository_file.dependabot_notify,
github_team.admins,
github_team_repository.admins,
]
}
# The relaxed profile retains pull-request-only writes and basic branch
# integrity, but does not require CI, approvals, code owners, or resolved
# conversations. Private repositories remain excluded from this resource.
resource "github_branch_protection" "relaxed_protections" {
for_each = {
for name, repository in local.repositories : name => repository
if !repository.archived && !repository.private && repository.protection_profile == "relaxed"
}
repository_id = github_repository.repositories[each.key].node_id
pattern = "main"
enforce_admins = true
allows_force_pushes = false
required_linear_history = true
required_pull_request_reviews {
require_code_owner_reviews = false
required_approving_review_count = 0
require_last_push_approval = false
}
restrict_pushes {
push_allowances = [
"${var.github_owner}/${github_team.admins.slug}"
]
}
depends_on = [
github_repository.repositories,
github_team.admins,
github_team_repository.admins,
]
}