Skip to content

Commit 353b601

Browse files
committed
docs: enhance enterprise ruleset examples with repository target support and conditions
1 parent 08d0262 commit 353b601

5 files changed

Lines changed: 123 additions & 4 deletions

File tree

examples/enterprise_rulesets/push_rulesets.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ resource "github_enterprise_ruleset" "push_restrictions" {
2525
# Target all organizations
2626
organization_name {
2727
include = ["~ALL"]
28+
exclude = []
2829
}
2930

3031
# Target all repositories
@@ -105,10 +106,12 @@ resource "github_enterprise_ruleset" "security_push_restrictions" {
105106
conditions {
106107
organization_name {
107108
include = ["~ALL"]
109+
exclude = []
108110
}
109111

110112
repository_name {
111113
include = ["*-prod", "*-production"]
114+
exclude = []
112115
}
113116
}
114117

examples/enterprise_rulesets/repository_ruleset.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,14 @@ resource "github_enterprise_ruleset" "org_id_repository_rules" {
108108
conditions {
109109
# Use organization_id instead of organization_name
110110
# This is useful when you know the specific org IDs
111-
organization_id = [123456, 789012]
111+
organization_id {
112+
organization_ids = [123456, 789012]
113+
}
112114

113115
# Use repository_id for specific repositories
114-
repository_id = [111111, 222222]
116+
repository_id {
117+
repository_ids = [111111, 222222]
118+
}
115119
}
116120

117121
rules {

examples/enterprise_rulesets/tag_ruleset.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ resource "github_enterprise_ruleset" "tag_protection" {
1919
# Target all organizations
2020
organization_name {
2121
include = ["~ALL"]
22+
exclude = []
2223
}
2324

2425
# Target all repositories
2526
repository_name {
2627
include = ["~ALL"]
28+
exclude = []
2729
}
2830

2931
# Target specific tag patterns (required for tag target)
@@ -83,15 +85,18 @@ resource "github_enterprise_ruleset" "dev_tag_protection" {
8385
conditions {
8486
organization_name {
8587
include = ["~ALL"]
88+
exclude = []
8689
}
8790

8891
repository_name {
8992
include = ["~ALL"]
93+
exclude = []
9094
}
9195

9296
# Only apply to development/snapshot tags
9397
ref_name {
9498
include = ["*-SNAPSHOT", "*-dev"]
99+
exclude = []
95100
}
96101
}
97102

website/docs/d/enterprise_ruleset.html.markdown

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ data "github_enterprise_ruleset" "example" {
2828

2929
- `name` - (String) The name of the ruleset.
3030

31-
- `target` - (String) The target of the ruleset. Possible values are `branch`, `tag`, and `push`.
31+
- `target` - (String) The target of the ruleset. Possible values are `branch`, `tag`, `push`, and `repository`.
3232

3333
- `enforcement` - (String) The enforcement level of the ruleset. Possible values are `disabled`, `active`, and `evaluate`.
3434

@@ -112,6 +112,8 @@ data "github_enterprise_ruleset" "example" {
112112

113113
- `pull_request` - (List) Require all commits be made to a non-target branch and submitted via a pull request. (see [below for nested schema](#rulespull_request))
114114

115+
- `copilot_code_review` - (List) Automatically request Copilot code review for new pull requests. (see [below for nested schema](#rulescopilot_code_review))
116+
115117
- `required_status_checks` - (List) Status checks that are required. (see [below for nested schema](#rulesrequired_status_checks))
116118

117119
- `required_workflows` - (List) Actions workflows that are required. (see [below for nested schema](#rulesrequired_workflows))
@@ -136,6 +138,16 @@ data "github_enterprise_ruleset" "example" {
136138

137139
- `file_extension_restriction` - (List) File extension restrictions for push rulesets. (see [below for nested schema](#rulesfile_extension_restriction))
138140

141+
- `repository_creation` - (Boolean) Only allow users with bypass permission to create repositories. Only valid for `repository` target.
142+
143+
- `repository_deletion` - (Boolean) Only allow users with bypass permission to delete repositories. Only valid for `repository` target.
144+
145+
- `repository_transfer` - (Boolean) Only allow users with bypass permission to transfer repositories. Only valid for `repository` target.
146+
147+
- `repository_name` - (List) Restrict repository names to match specified patterns. Only valid for `repository` target. (see [below for nested schema](#rulesrepository_name))
148+
149+
- `repository_visibility` - (List) Restrict repository visibility changes. Only valid for `repository` target. (see [below for nested schema](#rulesrepository_visibility))
150+
139151
### rules.pull_request
140152

141153
- `dismiss_stale_reviews_on_push` - (Boolean) New, reviewable commits pushed will dismiss previous pull request review approvals.
@@ -148,22 +160,36 @@ data "github_enterprise_ruleset" "example" {
148160

149161
- `required_review_thread_resolution` - (Boolean) All conversations on code must be resolved before a pull request can be merged.
150162

163+
- `allowed_merge_methods` - (List of String) The merge methods allowed for pull requests. Possible values are `merge`, `squash`, and `rebase`.
164+
165+
### rules.copilot_code_review
166+
167+
- `review_on_push` - (Boolean) Copilot automatically reviews each new push to the pull request.
168+
169+
- `review_draft_pull_requests` - (Boolean) Copilot automatically reviews draft pull requests before they are marked as ready for review.
170+
151171
### rules.required_status_checks
152172

153173
- `required_check` - (List) Status checks that are required. (see [below for nested schema](#rulesrequired_status_checksrequired_check))
154174

155175
- `strict_required_status_checks_policy` - (Boolean) Whether pull requests targeting a matching branch must be tested with the latest code.
156176

177+
- `do_not_enforce_on_create` - (Boolean) Allow repositories and branches to be created if a check would otherwise prohibit it.
178+
157179
### rules.required_status_checks.required_check
158180

159181
- `context` - (String) The status check context name that must be present on the commit.
160182

161183
- `integration_id` - (Number) The optional integration ID that this status check must originate from.
162184

185+
- `do_not_enforce_on_create` - (Boolean) Allow repositories and branches to be created if a check would otherwise prohibit it.
186+
163187
### rules.required_workflows
164188

165189
- `required_workflow` - (List) Actions workflows that are required. (see [below for nested schema](#rulesrequired_workflowsrequired_workflow))
166190

191+
- `do_not_enforce_on_create` - (Boolean) Allow repositories and branches to be created if a check would otherwise prohibit it.
192+
167193
### rules.required_workflows.required_workflow
168194

169195
- `repository_id` - (Number) The ID of the repository.
@@ -249,3 +275,15 @@ data "github_enterprise_ruleset" "example" {
249275
### rules.file_extension_restriction
250276

251277
- `restricted_file_extensions` - (List of String) The file extensions that are restricted from being pushed to the commit graph.
278+
279+
### rules.repository_name
280+
281+
- `pattern` - (String) The pattern to match repository names against.
282+
283+
- `negate` - (Boolean) If true, the rule will fail if the pattern matches.
284+
285+
### rules.repository_visibility
286+
287+
- `internal` - (Boolean) Allow internal visibility for repositories.
288+
289+
- `private` - (Boolean) Allow private visibility for repositories.

website/docs/r/enterprise_ruleset.html.markdown

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,58 @@ resource "github_enterprise_ruleset" "commit_patterns" {
266266
}
267267
```
268268

269+
### Repository Target Ruleset
270+
271+
```hcl
272+
resource "github_enterprise_ruleset" "repository_management" {
273+
enterprise_slug = "my-enterprise"
274+
name = "repository-management"
275+
target = "repository"
276+
enforcement = "active"
277+
278+
bypass_actors {
279+
actor_id = 1
280+
actor_type = "OrganizationAdmin"
281+
bypass_mode = "always"
282+
}
283+
284+
conditions {
285+
organization_name {
286+
include = ["~ALL"]
287+
exclude = []
288+
}
289+
290+
repository_name {
291+
include = ["~ALL"]
292+
exclude = []
293+
}
294+
}
295+
296+
rules {
297+
repository_creation = true
298+
repository_deletion = true
299+
repository_transfer = true
300+
301+
repository_name {
302+
pattern = "^[a-z][a-z0-9-]*$"
303+
negate = false
304+
}
305+
306+
repository_visibility {
307+
internal = true
308+
private = true
309+
}
310+
}
311+
}
312+
```
313+
269314
## Argument Reference
270315

271316
- `enterprise_slug` - (Required) (String) The slug of the enterprise.
272317

273318
- `name` - (Required) (String) The name of the ruleset.
274319

275-
- `target` - (Required) (String) Possible values are `branch`, `tag` and `push`. Note: The `push` target is in beta and is subject to change.
320+
- `target` - (Required) (String) Possible values are `branch`, `tag`, `push`, and `repository`. Note: The `push` and `repository` targets are in beta and are subject to change.
276321

277322
- `enforcement` - (Required) (String) Possible values for Enforcement are `disabled`, `active`, `evaluate`. Note: `evaluate` is currently only supported for owners of type `organization`.
278323

@@ -326,6 +371,16 @@ The `rules` block supports the following:
326371

327372
- `file_extension_restriction` - (Optional) (Block List, Max: 1) Prevent commits that include files with specified file extensions from being pushed to the commit graph. This rule only applies to rulesets with target `push`. (see [below for nested schema](#rulesfile_extension_restriction))
328373

374+
- `repository_creation` - (Optional) (Boolean) Only allow users with bypass permission to create repositories. Only valid for `repository` target.
375+
376+
- `repository_deletion` - (Optional) (Boolean) Only allow users with bypass permission to delete repositories. Only valid for `repository` target.
377+
378+
- `repository_transfer` - (Optional) (Boolean) Only allow users with bypass permission to transfer repositories. Only valid for `repository` target.
379+
380+
- `repository_name` - (Optional) (Block List, Max: 1) Restrict repository names to match specified patterns. Only valid for `repository` target. (see [below for nested schema](#rulesrepository_name))
381+
382+
- `repository_visibility` - (Optional) (Block List, Max: 1) Restrict repository visibility changes. Only valid for `repository` target. (see [below for nested schema](#rulesrepository_visibility))
383+
329384
#### rules.pull_request
330385

331386
- `dismiss_stale_reviews_on_push` - (Optional) (Boolean) New, reviewable commits pushed will dismiss previous pull request review approvals. Defaults to `false`.
@@ -338,6 +393,8 @@ The `rules` block supports the following:
338393

339394
- `required_review_thread_resolution` - (Optional) (Boolean) All conversations on code must be resolved before a pull request can be merged. Defaults to `false`.
340395

396+
- `allowed_merge_methods` - (Optional) (List of String, Min: 1) The merge methods allowed for pull requests. Possible values are `merge`, `squash`, and `rebase`.
397+
341398
#### rules.copilot_code_review
342399

343400
- `review_on_push` - (Optional) (Boolean) Copilot automatically reviews each new push to the pull request. Defaults to `false`.
@@ -452,6 +509,18 @@ The `rules` block supports the following:
452509

453510
- `restricted_file_extensions` - (Required) (List of String, Min: 1) The file extensions that are restricted from being pushed to the commit graph.
454511

512+
#### rules.repository_name
513+
514+
- `pattern` - (Required) (String) The pattern to match repository names against.
515+
516+
- `negate` - (Optional) (Boolean) If true, the rule will fail if the pattern matches. Defaults to `false`.
517+
518+
#### rules.repository_visibility
519+
520+
- `internal` - (Optional) (Boolean) Allow internal visibility for repositories. Defaults to `false`.
521+
522+
- `private` - (Optional) (Boolean) Allow private visibility for repositories. Defaults to `false`.
523+
455524
### bypass_actors
456525

457526
- `actor_id` - (Optional) (Number) The ID of the actor that can bypass a ruleset. When `actor_type` is `OrganizationAdmin`, this should be set to `1`. Some resources such as DeployKey do not have an ID and this should be omitted.

0 commit comments

Comments
 (0)