You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Refactor module to single-repo pattern with configurable branch protection, and autolink support (#7)
* feat: Refactor module to single-repo pattern with configurable branch protection, and autolink support
* chore: Remove unnecessary args in pre-commit-config
Copy file name to clipboardExpand all lines: README.md
+57-42Lines changed: 57 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,64 +1,80 @@
1
1
# Terraform GitHub Repository
2
2
3
-
Creates a GitHub repository.
3
+
Creates a GitHub repository with strong, opinionated branch protection for the default branch.
4
4
5
-
This module is very opinionated and possibly not suitable for other use cases.
5
+
By default, this module:
6
6
7
-
It creates one or more GitHub repositories with a ruleset protecting the main branch.
7
+
- Blocks force pushes and branch deletions
8
+
- Requires a linear commit history and signed commits
9
+
- Optionally enforces pull request reviews (see variables)
10
+
11
+
If your use case requires custom or no branch protection, set `enable_default_ruleset = false` and use the [`github_repository_ruleset`](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_ruleset) resource directly in your configuration.
8
12
9
13
## Usage
10
14
11
15
```hcl
12
-
module "repositories" {
16
+
module "repository" {
13
17
source = "terraform-github-repository"
18
+
name = "example-repo"
14
19
15
-
repositories = [
16
-
{
17
-
name = "test"
18
-
},
19
-
{
20
-
name = "test2"
21
-
repo_visibility = "public"
22
-
}
23
-
]
20
+
pr_require_code_owner_review = true
21
+
pr_required_approving_review_count = 1
24
22
}
25
-
26
23
```
27
24
25
+
**Note:** If you set `pr_require_code_owner_review = true`, you must add a `CODEOWNERS` file to your repository or PR merges will be blocked.
26
+
28
27
<!-- BEGIN_TF_DOCS -->
29
28
***
30
29
31
30
## Inputs
32
31
33
32
| Name | Description | Type | Default | Required |
| repo_name | Name of repository. |`string`| n/a | yes |
36
-
| allow_auto_merge | value |`bool`|`false`| no |
37
-
| allow_merge_commit | value |`bool`|`false`| no |
38
-
| allow_rebase_merge | value |`bool`|`false`| no |
39
-
| allow_squash_merge | value |`bool`|`true`| no |
40
-
| allow_update_branch | value |`bool`|`true`| no |
41
-
| archived | value |`bool`|`false`| no |
42
-
| auto_init | value |`bool`|`false`| no |
43
-
| default_branch_name | Name of default branch. |`string`|`"main"`| no |
44
-
| delete_branch_on_merge | value |`bool`|`true`| no |
45
-
| has_discussions | value |`bool`|`false`| no |
46
-
| has_downloads | value |`bool`|`false`| no |
47
-
| has_issues | value |`bool`|`true`| no |
48
-
| has_projects | value |`bool`|`false`| no |
49
-
| has_wiki | value |`bool`|`false`| no |
50
-
| is_template | value |`bool`|`false`| no |
51
-
| repo_description | Description of the repository. Displayed in right-hand column on repo home page. |`string`|`""`| no |
52
-
| repo_visibility | Whether repo should be `public` or `private`. |`string`|`"private"`| no |
53
-
| vulnerability_alerts | value |`bool`|`true`| no |
54
-
| web_commit_signoff_required | value |`bool`|`false`| no |
34
+
| name | Name of the repository. |`string`| n/a | yes |
35
+
| allow_auto_merge | Whether auto-merge is allowed. |`bool`|`false`| no |
36
+
| allow_merge_commit | Whether merge commits are allowed. |`bool`|`false`| no |
37
+
| allow_rebase_merge | Whether rebase merges are allowed. |`bool`|`false`| no |
38
+
| allow_squash_merge | Whether squash merges are allowed. |`bool`|`true`| no |
39
+
| allow_update_branch | Whether branches can be updated automatically. |`bool`|`true`| no |
40
+
| archived | Whether the repository is archived. |`bool`|`false`| no |
41
+
| auto_init | Whether an initial commit is automatically produced in the repository. |`bool`|`false`| no |
42
+
| autolink_reference_prefix | This prefix appended by a number generates a link any time it is found in an issue, PR, or commit. Required if `autolink_reference_url_template` is set. |`string`|`""`| no |
43
+
| autolink_reference_url_template | The target URL template for the autolink reference. Use `<num>` as a placeholder for the number. Required if `autolink_reference_prefix` is set. |`string`|`""`| no |
44
+
| default_branch_name | Name of the default branch. |`string`|`"main"`| no |
45
+
| delete_branch_on_merge | Whether to delete branch on merge. |`bool`|`true`| no |
46
+
| description | Description of the repository. |`string`|`""`| no |
47
+
| enable_default_ruleset | Whether to create a secure default branch protection ruleset. |`bool`|`true`| no |
48
+
| has_discussions | Whether the repository has discussions enabled. |`bool`|`false`| no |
49
+
| has_downloads | Whether the repository has downloads enabled. |`bool`|`false`| no |
50
+
| has_issues | Whether the repository has issues enabled. |`bool`|`true`| no |
51
+
| has_projects | Whether the repository has projects enabled. |`bool`|`false`| no |
52
+
| has_wiki | Whether the repository has wiki enabled. |`bool`|`false`| no |
53
+
| is_template | Whether the repository is a template. |`bool`|`false`| no |
54
+
| pr_dismiss_stale_reviews_on_push | Whether to dismiss stale reviews on a PR when new commits are pushed. |`bool`|`true`| no |
55
+
| pr_require_code_owner_review | Whether to require code owner review on a PR before merging. |`bool`|`false`| no |
56
+
| pr_require_last_push_approval | Whether the most recent pusher to a PR must approve the PR. |`bool`|`false`| no |
57
+
| pr_required_approving_review_count | Number of required PR approving reviews. |`number`|`0`| no |
58
+
| pr_required_review_thread_resolution | Whether to require all review threads on a PR to be resolved before merging. |`bool`|`false`| no |
59
+
| rules_creation | If true, only allows users with bypass permission to create matching refs. |`bool`|`false`| no |
60
+
| rules_deletion | If true, only allows users with bypass permissions to delete matching refs. |`bool`|`true`| no |
61
+
| rules_non_fast_forward | If true, prevents users with push access from force pushing to branches. |`bool`|`true`| no |
62
+
| rules_required_linear_history | If true, prevents merge commits from being pushed to matching branches. In other words, any PRs merged into the branch must use a squash merge or a rebase merge. |`bool`|`true`| no |
63
+
| rules_required_signatures | If true, commits pushed to matching branches must have verified signatures. |`bool`|`true`| no |
64
+
| rules_update | If true, only allows users with bypass permission to update matching refs. |`bool`|`false`| no |
65
+
| rules_update_allows_fetch_and_merge | If true, the branch can pull changes from its upstream repository. This is only applicable to forked repositories. Requires `update` to be set to true. |`bool`|`false`| no |
66
+
| topics | A list of topics for the repository. |`list(string)`|`[]`| no |
67
+
| visibility | Repository visibility: private, public, or internal. |`string`|`"private"`| no |
68
+
| vulnerability_alerts | Whether to enable vulnerability alerts. |`bool`|`true`| no |
69
+
| web_commit_signoff_required | Whether contributor signoff is required on web commits. |`bool`|`false`| no |
55
70
56
71
## Outputs
57
72
58
73
| Name | Description |
59
74
|------|-------------|
60
-
| kms_key_arn | The ARN for the CMK KMS key used for CloudWatch encryption. |
0 commit comments