Skip to content

Commit ca8a0b6

Browse files
authored
Support branches and pages for repository module (#4)
1 parent 4509928 commit ca8a0b6

File tree

5 files changed

+96
-7
lines changed

5 files changed

+96
-7
lines changed

modules/repository/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ No modules.
3131

3232
| Name | Type |
3333
|------|------|
34+
| [github_branch.this](https://registry.terraform.io/providers/hashicorp/github/latest/docs/resources/branch) | resource |
3435
| [github_branch_default.this](https://registry.terraform.io/providers/hashicorp/github/latest/docs/resources/branch_default) | resource |
3536
| [github_issue_label.this](https://registry.terraform.io/providers/hashicorp/github/latest/docs/resources/issue_label) | resource |
3637
| [github_repository.this](https://registry.terraform.io/providers/hashicorp/github/latest/docs/resources/repository) | resource |
@@ -47,6 +48,7 @@ No modules.
4748
| <a name="input_admin_teams"></a> [admin\_teams](#input\_admin\_teams) | (Optional) A list of teams with `admin` permission to the repository. You can use GitHub team id or the GitHub team slug. | `set(string)` | `[]` | no |
4849
| <a name="input_archive_on_destroy"></a> [archive\_on\_destroy](#input\_archive\_on\_destroy) | (Optional) Set to `true` to archive the repository instead of deleting on destroy. | `bool` | `false` | no |
4950
| <a name="input_archived"></a> [archived](#input\_archived) | (Optional) Specify if the repository should be archived. Defaults to `false`. NOTE: Currently, the API does not support unarchiving. | `bool` | `false` | no |
51+
| <a name="input_branches"></a> [branches](#input\_branches) | (Optional) A list of branches to create and manage within the repository. | `set(string)` | `[]` | no |
5052
| <a name="input_default_branch"></a> [default\_branch](#input\_default\_branch) | (Optional) Set the default branch for the repository. Default is `main` branch. | `string` | `"main"` | no |
5153
| <a name="input_delete_branch_on_merge"></a> [delete\_branch\_on\_merge](#input\_delete\_branch\_on\_merge) | (Optional) Automatically delete head branch after a pull request is merged. Defaults to true. | `bool` | `true` | no |
5254
| <a name="input_deploy_keys"></a> [deploy\_keys](#input\_deploy\_keys) | (Optional) A list of deploy keys to grant access to the repository. A deploy key is a SSH key. Each member of `deploy_keys` block as defined below.<br> (Required) `name` - A name of deploy key.<br> (Optional) `key` - A SSH key. Begins with 'ssh-rsa', 'ecdsa-sha2-nistp256', 'ecdsa-sha2-nistp384', 'ecdsa-sha2-nistp521', 'ssh-ed25519', '[email protected]', or '[email protected]'.<br> (Optional) `writable` - Whether to allow write access to the repository. The key can be used to push to the repository if enabled. | <pre>list(object({<br> name = string<br> key = string<br> writable = bool<br> }))</pre> | `[]` | no |
@@ -58,13 +60,18 @@ No modules.
5860
| <a name="input_maintain_collaborators"></a> [maintain\_collaborators](#input\_maintain\_collaborators) | (Optional) A list of users as collaborator with `maintain` permission to the repository. You can use GitHub username. | `set(string)` | `[]` | no |
5961
| <a name="input_maintain_teams"></a> [maintain\_teams](#input\_maintain\_teams) | (Optional) A list of teams with `maintain` permission to the repository. You can use GitHub team id or the GitHub team slug. | `set(string)` | `[]` | no |
6062
| <a name="input_merge_strategies"></a> [merge\_strategies](#input\_merge\_strategies) | (Optional) A list of allowed strategies for merging pull requests on the repository. Available strategies: `MERGE_COMMIT`, `SQUASH`, `REBASE`. | `set(string)` | <pre>[<br> "SQUASH",<br> "REBASE"<br>]</pre> | no |
63+
| <a name="input_pages_cname"></a> [pages\_cname](#input\_pages\_cname) | (Optional) The custom domain for the repository. This can only be set after the repository has been created. | `string` | `null` | no |
64+
| <a name="input_pages_enabled"></a> [pages\_enabled](#input\_pages\_enabled) | (Optional) Set to true to enable GitHub Pages for the repository. GitHub Pages is designed to host your personal, organization, or project pages from a GitHub repository. | `bool` | `false` | no |
65+
| <a name="input_pages_source_branch"></a> [pages\_source\_branch](#input\_pages\_source\_branch) | (Optional) The repository branch used to publish the site's source files. Defaults to `gh-pages` branch. | `string` | `"gh-pages"` | no |
66+
| <a name="input_pages_source_path"></a> [pages\_source\_path](#input\_pages\_source\_path) | (Optional) The repository directory path from which the site publishes. Defaults to `/`. | `string` | `"/"` | no |
6167
| <a name="input_read_collaborators"></a> [read\_collaborators](#input\_read\_collaborators) | (Optional) A list of users as collaborator with `read` permission to the repository. You can use GitHub username. | `set(string)` | `[]` | no |
6268
| <a name="input_read_teams"></a> [read\_teams](#input\_read\_teams) | (Optional) A list of teams with `read` permission to the repository. You can use GitHub team id or the GitHub team slug. | `set(string)` | `[]` | no |
6369
| <a name="input_template"></a> [template](#input\_template) | (Optional) Use a template repository, license or gitignore to create the repository.this resource. `template` block as defined below.<br> (Optional) `gitignore` - Choose which files not to track from a list of templates. Use the name of the template without the extension. For example, `Haskell`.<br> (Optional) `init_readme` - Set to `true` to produce an initial commit with README.md in the repository.<br> (Optional) `license` - A license tells others what they can and can't do with your code. Use the name of the license template without the extension. For example, `mit` or `mpl-2.0`.<br> (Optional) `repository` - Start this repository with a template repository's contents. The full name of the repository is required. A string of the form `owner/repository`. | `any` | `{}` | no |
6470
| <a name="input_topics"></a> [topics](#input\_topics) | (Optional) A list of topics for the repository. | `set(string)` | `[]` | no |
6571
| <a name="input_triage_collaborators"></a> [triage\_collaborators](#input\_triage\_collaborators) | (Optional) A list of users as collaborator with `triage` permission to the repository. You can use GitHub username. | `set(string)` | `[]` | no |
6672
| <a name="input_triage_teams"></a> [triage\_teams](#input\_triage\_teams) | (Optional) A list of teams with `triage` permission to the repository. You can use GitHub team id or the GitHub team slug. | `set(string)` | `[]` | no |
6773
| <a name="input_visibility"></a> [visibility](#input\_visibility) | (Optional) Can be `public`, `private` or `internal`. `internal` visibility is only available if your organization is associated with an enterprise account using GitHub Enterprise Cloud or GitHub Enterprise Server 2.20+. | `string` | `"private"` | no |
74+
| <a name="input_vulnerability_alerts"></a> [vulnerability\_alerts](#input\_vulnerability\_alerts) | (Optional) Set to true to enable security alerts for vulnerable dependencies. Enabling requires alerts to be enabled on the owner level. GitHub enables the alerts on public repos but disables them on private repos by default. | `bool` | `false` | no |
6875
| <a name="input_write_collaborators"></a> [write\_collaborators](#input\_write\_collaborators) | (Optional) A list of users as collaborator with `write` permission to the repository. You can use GitHub username. | `set(string)` | `[]` | no |
6976
| <a name="input_write_teams"></a> [write\_teams](#input\_write\_teams) | (Optional) A list of teams with `write` permission to the repository. You can use GitHub team id or the GitHub team slug. | `set(string)` | `[]` | no |
7077

@@ -73,6 +80,7 @@ No modules.
7380
| Name | Description |
7481
|------|-------------|
7582
| <a name="output_archived"></a> [archived](#output\_archived) | Whether the repository is archived. |
83+
| <a name="output_branches"></a> [branches](#output\_branches) | A list of the repository branches excluding initial branch. |
7684
| <a name="output_default_branch"></a> [default\_branch](#output\_default\_branch) | The default branch of the repository. |
7785
| <a name="output_delete_branch_on_merge"></a> [delete\_branch\_on\_merge](#output\_delete\_branch\_on\_merge) | Automatically delete head branch after a pull request is merged. |
7886
| <a name="output_deploy_keys"></a> [deploy\_keys](#output\_deploy\_keys) | A list of deploy keys granted access to the repository. |
@@ -88,10 +96,12 @@ No modules.
8896
| <a name="output_merge_strategies"></a> [merge\_strategies](#output\_merge\_strategies) | A list of available strategies for merging pull requests on the repository. |
8997
| <a name="output_name"></a> [name](#output\_name) | The name of the repository. |
9098
| <a name="output_node_id"></a> [node\_id](#output\_node\_id) | The node ID of the GitHub repository. This is GraphQL global node id for use with v4 API. |
99+
| <a name="output_pages"></a> [pages](#output\_pages) | The repository's GitHub Pages configuration. |
91100
| <a name="output_permissions"></a> [permissions](#output\_permissions) | The access control list which manage individual and team access to the repository. |
92101
| <a name="output_ssh_clone_url"></a> [ssh\_clone\_url](#output\_ssh\_clone\_url) | The URL that can be provided to `git clone` to clone the repository anonymously via SSH. |
93102
| <a name="output_template"></a> [template](#output\_template) | The template of the repository. |
94103
| <a name="output_topics"></a> [topics](#output\_topics) | A list of topics for the repository. |
95104
| <a name="output_url"></a> [url](#output\_url) | The URL of the repository. |
96105
| <a name="output_visibility"></a> [visibility](#output\_visibility) | The visibility of the repository. Can be `public`, `private` or `internal`. |
106+
| <a name="output_vulnerability_alerts"></a> [vulnerability\_alerts](#output\_vulnerability\_alerts) | Whether the security alerts are enabled for vulnerable dpendencies. |
97107
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

modules/repository/branches.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
resource "github_branch_default" "this" {
2+
count = var.default_branch != null ? 1 : 0
3+
4+
repository = github_repository.this.name
5+
branch = var.default_branch
6+
7+
depends_on = [github_branch.this]
8+
}
9+
10+
resource "github_branch" "this" {
11+
for_each = toset(var.branches)
12+
13+
repository = github_repository.this.name
14+
branch = each.value
15+
}

modules/repository/main.tf

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,22 @@ resource "github_repository" "this" {
3030
allow_rebase_merge = contains(var.merge_strategies, "REBASE")
3131

3232
delete_branch_on_merge = var.delete_branch_on_merge
33+
vulnerability_alerts = var.vulnerability_alerts
3334

3435
topics = var.topics
3536

37+
dynamic "pages" {
38+
for_each = var.pages_enabled ? ["go"] : []
39+
40+
content {
41+
source {
42+
branch = var.pages_source_branch
43+
path = var.pages_source_path
44+
}
45+
cname = try(var.pages_cname, null)
46+
}
47+
}
48+
3649
lifecycle {
3750
ignore_changes = [
3851
auto_init,
@@ -42,10 +55,3 @@ resource "github_repository" "this" {
4255
]
4356
}
4457
}
45-
46-
resource "github_branch_default" "this" {
47-
count = var.default_branch != null ? 1 : 0
48-
49-
repository = github_repository.this.name
50-
branch = var.default_branch
51-
}

modules/repository/outputs.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,37 @@ output "permissions" {
125125
}
126126
}
127127

128+
output "branches" {
129+
description = "A list of the repository branches excluding initial branch."
130+
value = var.branches
131+
}
132+
128133
output "default_branch" {
129134
description = "The default branch of the repository."
130135
value = one(github_branch_default.this.*.branch)
131136
}
132137

138+
output "vulnerability_alerts" {
139+
description = "Whether the security alerts are enabled for vulnerable dpendencies."
140+
value = github_repository.this.vulnerability_alerts
141+
}
142+
133143
output "deploy_keys" {
134144
description = "A list of deploy keys granted access to the repository."
135145
value = {
136146
for key in var.deploy_keys :
137147
key.name => key
138148
}
139149
}
150+
151+
output "pages" {
152+
description = "The repository's GitHub Pages configuration."
153+
value = {
154+
eanbled = var.pages_enabled
155+
cname = var.pages_cname
156+
source = {
157+
branch = var.pages_source_branch
158+
path = var.pages_source_path
159+
}
160+
}
161+
}

modules/repository/variables.tf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,24 @@ variable "admin_collaborators" {
164164
default = []
165165
}
166166

167+
variable "branches" {
168+
description = "(Optional) A list of branches to create and manage within the repository."
169+
type = set(string)
170+
default = []
171+
}
172+
167173
variable "default_branch" {
168174
description = "(Optional) Set the default branch for the repository. Default is `main` branch."
169175
type = string
170176
default = "main"
171177
}
172178

179+
variable "vulnerability_alerts" {
180+
description = "(Optional) Set to true to enable security alerts for vulnerable dependencies. Enabling requires alerts to be enabled on the owner level. GitHub enables the alerts on public repos but disables them on private repos by default."
181+
type = bool
182+
default = false
183+
}
184+
173185
variable "deploy_keys" {
174186
description = <<EOF
175187
(Optional) A list of deploy keys to grant access to the repository. A deploy key is a SSH key. Each member of `deploy_keys` block as defined below.
@@ -184,3 +196,27 @@ variable "deploy_keys" {
184196
}))
185197
default = []
186198
}
199+
200+
variable "pages_enabled" {
201+
description = "(Optional) Set to true to enable GitHub Pages for the repository. GitHub Pages is designed to host your personal, organization, or project pages from a GitHub repository."
202+
type = bool
203+
default = false
204+
}
205+
206+
variable "pages_source_branch" {
207+
description = "(Optional) The repository branch used to publish the site's source files. Defaults to `gh-pages` branch."
208+
type = string
209+
default = "gh-pages"
210+
}
211+
212+
variable "pages_source_path" {
213+
description = "(Optional) The repository directory path from which the site publishes. Defaults to `/`."
214+
type = string
215+
default = "/"
216+
}
217+
218+
variable "pages_cname" {
219+
description = "(Optional) The custom domain for the repository. This can only be set after the repository has been created."
220+
type = string
221+
default = null
222+
}

0 commit comments

Comments
 (0)