Skip to content

Commit 90d6554

Browse files
committed
Refactor repository module
1 parent 6b62457 commit 90d6554

File tree

4 files changed

+84
-62
lines changed

4 files changed

+84
-62
lines changed

modules/repository/README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,22 @@ No modules.
5151
|------|-------------|------|---------|:--------:|
5252
| <a name="input_name"></a> [name](#input\_name) | (Required) A name of the repository. | `string` | n/a | yes |
5353
| <a name="input_access"></a> [access](#input\_access) | (Optional) A configuration for the repository access. `access` block as defined below.<br> (Optional) `collaborators` - A list of collaborators to the repository. Each item of `collaborators` block as defined below.<br> (Required) `username` - The GitHub username to add to the repository as a collaborator.<br> (Optional) `role` - The role to grant the collaborator in the repository. Valid values are `read`, `triage`, `write`, `maintain`, `admin` or the name of an existing custom repository role within the organisation. Default is `write`.<br> (Optional) `teams` - A list of teams to the repository. Each item of `teams` block as defined below.<br> (Required) `team` - The GitHub team id or the GitHub team slug.<br> (Optional) `role` - The role to grant the team in the repository. Valid values are `read`, `triage`, `write`, `maintain`, `admin` or the name of an existing custom repository role within the organisation. Default is `read`.<br> (Optional) `sync_enabled` - Whether to sync the repository access. Accesses added outside of the Terraform code will be removed. Defaults to `false`. | <pre>object({<br> collaborators = optional(list(object({<br> username = string<br> role = optional(string, "write")<br> })), [])<br> teams = optional(list(object({<br> team = string<br> role = optional(string, "read")<br> })), [])<br> sync_enabled = optional(bool, false)<br> })</pre> | `{}` | no |
54-
| <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 |
54+
| <a name="input_archive_on_destroy"></a> [archive\_on\_destroy](#input\_archive\_on\_destroy) | (Optional) Whether to archive the repository instead of deleting on destroy. Defaults to `false`. | `bool` | `false` | no |
5555
| <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 |
56+
| <a name="input_auto_merge_enabled"></a> [auto\_merge\_enabled](#input\_auto\_merge\_enabled) | (Optional) Whether to wait for merge requirements to be met and then merge automatically. Defaults to `false`. | `bool` | `false` | no |
5657
| <a name="input_autolink_references"></a> [autolink\_references](#input\_autolink\_references) | (Optional) A list of autolink references for the repository. Each item of `autolink_references` block as defined below.<br> (Required) `key_prefix` - This prefix appended by a string will generate a link any time it is found in an issue, pull request, or commit.<br> (Required) `target_url_template` - The URL must contain <num> for the reference number.<br> (Optional) `is_alphanumeric` - Whether this autolink reference matches alphanumeric characters. If false, this autolink reference only matches numeric characters. Defaults to `false`. | <pre>set(object({<br> key_prefix = string<br> target_url_template = string<br> is_alphanumeric = optional(bool, false)<br> }))</pre> | `[]` | no |
5758
| <a name="input_branches"></a> [branches](#input\_branches) | (Optional) A list of branches to create and manage within the repository. | `set(string)` | `[]` | no |
5859
| <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 |
5960
| <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 |
6061
| <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 item of `deploy_keys` block as defined below.<br> (Optional) `name` - A name of deploy key.<br> (Required) `key` - A SSH key. Begins with 'ssh-rsa', 'ecdsa-sha2-nistp256', 'ecdsa-sha2-nistp384', 'ecdsa-sha2-nistp521', 'ssh-ed25519', 'sk-ecdsa-sha2-nistp256@openssh.com', or 'sk-ssh-ed25519@openssh.com'.<br> (Optional) `writable` - Whether to allow write access to the repository. The key can be used to push to the repository if enabled. Defaults to `false`. | <pre>list(object({<br> name = optional(string)<br> key = string<br> writable = optional(bool, false)<br> }))</pre> | `[]` | no |
6162
| <a name="input_description"></a> [description](#input\_description) | (Optional) A description of the repository. | `string` | `"Managed by Terraform."` | no |
62-
| <a name="input_features"></a> [features](#input\_features) | (Optional) A list of enabled features on the repository. Available features: `ISSUES`, `PROJECTS`, `WIKI`. | `set(string)` | <pre>[<br> "ISSUES"<br>]</pre> | no |
63-
| <a name="input_homepage"></a> [homepage](#input\_homepage) | (Optional) A URL of website describing the repository. | `string` | `null` | no |
64-
| <a name="input_is_template"></a> [is\_template](#input\_is\_template) | (Optional) Set to `true` if this is a template repository. | `bool` | `false` | no |
63+
| <a name="input_features"></a> [features](#input\_features) | (Optional) A list of enabled features on the repository. Available features: `ISSUES`, `PROJECTS`, `WIKI`. Defaults to `["ISSUES"]` | `set(string)` | <pre>[<br> "ISSUES"<br>]</pre> | no |
64+
| <a name="input_homepage"></a> [homepage](#input\_homepage) | (Optional) A URL of website describing the repository. | `string` | `""` | no |
65+
| <a name="input_is_template"></a> [is\_template](#input\_is\_template) | (Optional) Whether this is a template repository. Defaults to `false`. | `bool` | `false` | no |
6566
| <a name="input_issue_labels"></a> [issue\_labels](#input\_issue\_labels) | (Optional) A list of issue labels for the repository. Each member of `issue_labels` block as defined below.<br> (Required) `name` - The name of the label.<br> (Required) `color` - A 6 character hex code, without the leading #, identifying the color of the label.<br> (Optional) `description` - A short description of the label. | <pre>set(object({<br> name = string<br> color = string<br> description = optional(string, "Managed by Terraform.")<br> }))</pre> | `[]` | no |
66-
| <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 |
67-
| <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 |
68-
| <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 |
69-
| <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 |
70-
| <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 |
71-
| <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 |
67+
| <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`. Defaults to `["SQUASH", "REBASE"]`. | `set(string)` | <pre>[<br> "SQUASH",<br> "REBASE"<br>]</pre> | no |
68+
| <a name="input_pages"></a> [pages](#input\_pages) | (Optional) A configuration of GitHub Pages for the repository. `pages` block as defined below.<br> (Optional) `enabled` - Whether to enable GitHub Pages for the repository. GitHub Pages is designed to host your personal, organization, or project pages from a GitHub repository. Defaults to `false`.<br> (Optional) `source` - A configuration of the repository source files for the site. `source` block as defined below.<br> (Optional) `branch` - The repository branch used to publish the site's source files. Defaults to `gh-pages` branch.<br> (Optional) `path` - The repository directory path from which the site publishes. Defaults to `/`.<br> (Optional) `cname` - The custom domain for the repository. This can only be set after the repository has been created. | <pre>object({<br> enabled = optional(bool, false)<br> source = optional(object({<br> branch = optional(string, "gh-pages")<br> path = optional(string, "/")<br> }), {})<br> cname = optional(string)<br> })</pre> | `{}` | no |
69+
| <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` - Whether to produce an initial commit with README.md in the repository. Defaults to `false`.<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`. | <pre>object({<br> gitignore = optional(string)<br> init_readme = optional(bool, false)<br> license = optional(string)<br> repository = optional(string)<br> })</pre> | `{}` | no |
7270
| <a name="input_topics"></a> [topics](#input\_topics) | (Optional) A list of topics for the repository. | `set(string)` | `[]` | no |
7371
| <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 |
7472
| <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 |
@@ -79,6 +77,7 @@ No modules.
7977
|------|-------------|
8078
| <a name="output_access"></a> [access](#output\_access) | The configuration for the repository access. |
8179
| <a name="output_archived"></a> [archived](#output\_archived) | Whether the repository is archived. |
80+
| <a name="output_auto_merge_enabled"></a> [auto\_merge\_enabled](#output\_auto\_merge\_enabled) | Whether to wait for merge requirements to be met and then merge automatically. |
8281
| <a name="output_autolink_references"></a> [autolink\_references](#output\_autolink\_references) | A list of autolink references for the repository. |
8382
| <a name="output_branches"></a> [branches](#output\_branches) | A list of the repository branches excluding initial branch. |
8483
| <a name="output_default_branch"></a> [default\_branch](#output\_default\_branch) | The default branch of the repository. |

modules/repository/main.tf

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,62 @@
1+
# INFO: Not supported attributes
2+
# - `private`
3+
# - `has_downloads`
14
# INFO: Use a separate resource
25
# - `topics`
6+
# - `default_branch`
37
resource "github_repository" "this" {
48
name = var.name
59
description = var.description
610
homepage_url = var.homepage
711

812
visibility = var.visibility
9-
is_template = var.is_template
1013
archived = var.archived
1114
archive_on_destroy = var.archive_on_destroy
1215

13-
auto_init = try(var.template.init_readme, false)
14-
license_template = try(var.template.license, null)
15-
gitignore_template = try(var.template.gitignore, null)
16+
17+
## Template
18+
is_template = var.is_template
19+
20+
auto_init = var.template.init_readme
21+
license_template = var.template.license
22+
gitignore_template = var.template.gitignore
1623

1724
dynamic "template" {
18-
for_each = try([var.template.repository], [])
25+
for_each = var.template.repository != null ? [var.template.repository] : []
1926

2027
content {
2128
owner = split("/", template.value)[0]
2229
repository = split("/", template.value)[1]
2330
}
2431
}
2532

33+
34+
## Features
2635
has_issues = contains(var.features, "ISSUES")
2736
has_projects = contains(var.features, "PROJECTS")
2837
has_wiki = contains(var.features, "WIKI")
2938

39+
40+
## Pull Request
3041
allow_merge_commit = contains(var.merge_strategies, "MERGE_COMMIT")
3142
allow_squash_merge = contains(var.merge_strategies, "SQUASH")
3243
allow_rebase_merge = contains(var.merge_strategies, "REBASE")
3344

45+
allow_auto_merge = var.auto_merge_enabled
3446
delete_branch_on_merge = var.delete_branch_on_merge
3547
vulnerability_alerts = var.vulnerability_alerts
3648

49+
50+
## Pages
3751
dynamic "pages" {
38-
for_each = var.pages_enabled ? ["go"] : []
52+
for_each = var.pages.enabled ? [var.pages] : []
3953

4054
content {
4155
source {
42-
branch = var.pages_source_branch
43-
path = var.pages_source_path
56+
branch = pages.value.source.branch
57+
path = pages.value.source.path
4458
}
45-
cname = try(var.pages_cname, null)
59+
cname = pages.value.cname
4660
}
4761
}
4862

@@ -53,6 +67,7 @@ resource "github_repository" "this" {
5367
gitignore_template,
5468
template,
5569
topics,
70+
has_downloads,
5671
]
5772
}
5873
}

modules/repository/outputs.tf

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ output "merge_strategies" {
7878
value = var.merge_strategies
7979
}
8080

81+
output "auto_merge_enabled" {
82+
description = "Whether to wait for merge requirements to be met and then merge automatically."
83+
value = github_repository.this.allow_auto_merge
84+
}
85+
8186
output "delete_branch_on_merge" {
8287
description = "Automatically delete head branch after a pull request is merged."
8388
value = github_repository.this.delete_branch_on_merge
@@ -148,12 +153,5 @@ output "deploy_keys" {
148153

149154
output "pages" {
150155
description = "The repository's GitHub Pages configuration."
151-
value = {
152-
eanbled = var.pages_enabled
153-
cname = var.pages_cname
154-
source = {
155-
branch = var.pages_source_branch
156-
path = var.pages_source_path
157-
}
158-
}
156+
value = var.pages
159157
}

0 commit comments

Comments
 (0)