Skip to content

Commit ebc5da6

Browse files
committed
feat(repository): support custom property
1 parent ace342f commit ebc5da6

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

modules/repository/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This module creates following resources.
55
- `github_repository`
66
- `github_repository_collaborator` (optional)
77
- `github_repository_collaborators` (optional)
8+
- `github_repository_custom_property` (optional)
89
- `github_repository_file` (optional)
910
- `github_team_repository` (optional)
1011
- `github_repository_autolink_reference` (optional)
@@ -44,6 +45,7 @@ This module creates following resources.
4445
| [github_repository_autolink_reference.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_autolink_reference) | resource |
4546
| [github_repository_collaborator.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_collaborator) | resource |
4647
| [github_repository_collaborators.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_collaborators) | resource |
48+
| [github_repository_custom_property.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_custom_property) | resource |
4749
| [github_repository_deploy_key.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_deploy_key) | resource |
4850
| [github_repository_file.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_file) | resource |
4951
| [github_repository_topics.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_topics) | resource |
@@ -59,6 +61,7 @@ This module creates following resources.
5961
| <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 |
6062
| <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 |
6163
| <a name="input_branches"></a> [branches](#input\_branches) | (Optional) A list of branches to create and manage within the repository. | `set(string)` | `[]` | no |
64+
| <a name="input_custom_properties"></a> [custom\_properties](#input\_custom\_properties) | (Optional) A map of custom properties to set for the repository. The key of the map is the name of the custom property. The value of `custom_properties` map as defined below.<br/> (Required) `type` - The type of the custom property. Can be one of `STRING`, `SINGLE_SELECT`, `MULTI_SELECT`, or `BOOL`.<br/> (Required) `value` - The value of the custom property. For `STRING` type, the value should be a list with one string item. For `SINGLE_SELECT` type, the value should be a list with one string item and the value must be one of the allowed values defined in the organization-level custom property with the same name. For `MULTI_SELECT` type, the value can be a list of string items and each value must be one of the allowed values defined in the organization-level custom property with the same name. For `BOOL` type, the value should be a list with one string item and the value must be either `true` or `false`. | <pre>map(object({<br/> type = string<br/> value = list(string)<br/> }))</pre> | `{}` | no |
6265
| <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 |
6366
| <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 |
6467
| <a name="input_description"></a> [description](#input\_description) | (Optional) A description of the repository. | `string` | `"Managed by Terraform."` | no |
@@ -83,6 +86,7 @@ This module creates following resources.
8386
| <a name="output_archived"></a> [archived](#output\_archived) | Whether the repository is archived. |
8487
| <a name="output_autolink_references"></a> [autolink\_references](#output\_autolink\_references) | A list of autolink references for the repository. |
8588
| <a name="output_branches"></a> [branches](#output\_branches) | A list of the repository branches excluding initial branch. |
89+
| <a name="output_custom_properties"></a> [custom\_properties](#output\_custom\_properties) | A map of custom properties defined for the repository. |
8690
| <a name="output_default_branch"></a> [default\_branch](#output\_default\_branch) | The default branch of the repository. |
8791
| <a name="output_deploy_keys"></a> [deploy\_keys](#output\_deploy\_keys) | A map of deploy keys granted access to the repository. |
8892
| <a name="output_description"></a> [description](#output\_description) | The description of the repository. |

modules/repository/main.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
locals {
2+
custom_property_value_types = {
3+
"STRING" = "string"
4+
"SINGLE_SELECT" = "single_select"
5+
"MULTI_SELECT" = "multi_select"
6+
"BOOL" = "true_false"
7+
}
8+
}
9+
10+
11+
###################################################
12+
# GitHub Repository
13+
###################################################
14+
115
# INFO: Not supported attributes
216
# - `private`
317
# INFO: Deprecated attributes
@@ -93,6 +107,24 @@ resource "github_repository" "this" {
93107
}
94108

95109

110+
###################################################
111+
# Custom Properties for GitHub Repository
112+
###################################################
113+
114+
resource "github_repository_custom_property" "this" {
115+
for_each = {
116+
for name, property in var.custom_properties :
117+
name => property
118+
}
119+
120+
repository = github_repository.this.name
121+
122+
property_name = each.key
123+
property_type = local.custom_property_value_types[each.value.type]
124+
property_value = each.value.value
125+
}
126+
127+
96128
###################################################
97129
# Files for GitHub Repository
98130
###################################################

modules/repository/outputs.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ output "default_branch" {
144144
value = one(github_branch_default.this[*].branch)
145145
}
146146

147+
output "custom_properties" {
148+
description = "A map of custom properties defined for the repository."
149+
value = {
150+
for name, property in github_repository_custom_property.this :
151+
name => {
152+
name = property.property_name
153+
type = property.property_type
154+
value = property.property_value
155+
}
156+
}
157+
}
158+
147159
output "files" {
148160
description = "A list of files created in the repository."
149161
value = {

modules/repository/variables.tf

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,46 @@ variable "default_branch" {
236236
default = "main"
237237
}
238238

239+
variable "custom_properties" {
240+
description = <<EOF
241+
(Optional) A map of custom properties to set for the repository. The key of the map is the name of the custom property. The value of `custom_properties` map as defined below.
242+
(Required) `type` - The type of the custom property. Can be one of `STRING`, `SINGLE_SELECT`, `MULTI_SELECT`, or `BOOL`.
243+
(Required) `value` - The value of the custom property. For `STRING` type, the value should be a list with one string item. For `SINGLE_SELECT` type, the value should be a list with one string item and the value must be one of the allowed values defined in the organization-level custom property with the same name. For `MULTI_SELECT` type, the value can be a list of string items and each value must be one of the allowed values defined in the organization-level custom property with the same name. For `BOOL` type, the value should be a list with one string item and the value must be either `true` or `false`.
244+
EOF
245+
type = map(object({
246+
type = string
247+
value = list(string)
248+
}))
249+
default = {}
250+
nullable = false
251+
252+
validation {
253+
condition = alltrue([
254+
for property in var.custom_properties :
255+
contains(["STRING", "SINGLE_SELECT", "MULTI_SELECT", "BOOL"], property.type)
256+
])
257+
error_message = "Valid values for `type` are `STRING`, `SINGLE_SELECT`, `MULTI_SELECT`, `BOOL`."
258+
}
259+
validation {
260+
condition = alltrue([
261+
for property in var.custom_properties :
262+
length(property.value) == 1
263+
if contains(["STRING", "SINGLE_SELECT", "BOOL"], property.type)
264+
])
265+
error_message = "For `STRING`, `SINGLE_SELECT`, and `BOOL` types, the value must be a list with one string item."
266+
}
267+
validation {
268+
condition = alltrue([
269+
for property in var.custom_properties :
270+
anytrue([
271+
property.type != "BOOL",
272+
(property.type == "BOOL" && contains(["true", "false"], property.value[0]))
273+
])
274+
])
275+
error_message = "For `BOOL` type, the value must be either `true` or `false`."
276+
}
277+
}
278+
239279
variable "files" {
240280
description = <<EOF
241281
(Optional) A list of files to create and manage within the repository. Each item of `files` block as defined below.

0 commit comments

Comments
 (0)