Skip to content

Commit 7eb69cf

Browse files
authored
feat: add custom_property block for repository resource (#9)
1 parent 752d7dc commit 7eb69cf

File tree

7 files changed

+925
-1
lines changed

7 files changed

+925
-1
lines changed

docs/resources/repository.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,64 @@ resource "github_repository" "example" {
4646
}
4747
```
4848

49+
## Example Usage with Custom Properties
50+
51+
```terraform
52+
# This example matches the user's requested format with native HCL lists
53+
resource "github_repository" "example" {
54+
name = "example"
55+
description = "My awesome codebase"
56+
57+
custom_property {
58+
name = "foo"
59+
value = ["bar"]
60+
}
61+
62+
custom_property {
63+
name = "boolean"
64+
value = ["false"]
65+
}
66+
67+
custom_property {
68+
name = "multiselect"
69+
value = ["goo", "zoo"]
70+
}
71+
72+
custom_property {
73+
name = "singleselect"
74+
value = ["acme"]
75+
}
76+
}
77+
```
78+
79+
## Example Usage with Collaborative Custom Property Management
80+
81+
The following example illustrates collaborative management of repository custom properties by setting `exclusive_custom_properties = false` and delegating an additional property to the standalone `github_repository_custom_property` resource.
82+
83+
```terraform
84+
# This example demonstrates collaborative management of repository custom properties.
85+
# It assumes the organization already defines the referenced custom properties.
86+
87+
resource "github_repository" "example" {
88+
name = "example-shared-custom-props"
89+
description = "Repository with collaboratively managed custom properties"
90+
91+
exclusive_custom_properties = false
92+
93+
custom_property {
94+
name = "deployment-environment"
95+
value = ["production"]
96+
}
97+
}
98+
99+
resource "github_repository_custom_property" "compliance" {
100+
repository = github_repository.example.name
101+
property_name = "compliance-tier"
102+
property_type = "string"
103+
property_value = ["regulated"]
104+
}
105+
```
106+
49107
<!-- schema generated by tfplugindocs -->
50108
## Schema
51109

@@ -63,9 +121,11 @@ resource "github_repository" "example" {
63121
- `archive_on_destroy` (Boolean) Set to 'true' to archive the repository instead of deleting on destroy.
64122
- `archived` (Boolean) Specifies if the repository should be archived. Defaults to 'false'. NOTE Currently, the API does not support unarchiving.
65123
- `auto_init` (Boolean) Set to 'true' to produce an initial commit in the repository.
124+
- `custom_property` (Block Set) Custom properties for the repository. (see [below for nested schema](#nestedblock--custom_property))
66125
- `default_branch` (String, Deprecated) Can only be set after initial repository creation, and only if the target branch exists
67126
- `delete_branch_on_merge` (Boolean) Automatically delete head branch after a pull request is merged. Defaults to 'false'.
68127
- `description` (String) A description of the repository.
128+
- `exclusive_custom_properties` (Boolean) Whether this resource exclusively manages all custom properties. Defaults to 'true'; if set to 'false', only properties defined in custom_property blocks will be managed by this resource, allowing collaborative management of custom property settings.
69129
- `gitignore_template` (String) Use the name of the template without the extension. For example, 'Haskell'.
70130
- `has_discussions` (Boolean) Set to 'true' to enable GitHub Discussions on the repository. Defaults to 'false'.
71131
- `has_downloads` (Boolean) Set to 'true' to enable the (deprecated) downloads features on the repository.
@@ -91,6 +151,7 @@ resource "github_repository" "example" {
91151

92152
### Read-Only
93153

154+
- `all_custom_properties` (Map of String) All custom properties set on the repository, including those not managed by this resource.
94155
- `etag` (String)
95156
- `full_name` (String) A string of the form 'orgname/reponame'.
96157
- `git_clone_url` (String) URL that can be provided to 'git clone' to clone the repository anonymously via the git protocol.
@@ -103,6 +164,15 @@ resource "github_repository" "example" {
103164
- `ssh_clone_url` (String) URL that can be provided to 'git clone' to clone the repository via SSH.
104165
- `svn_url` (String) URL that can be provided to 'svn checkout' to check out the repository via GitHub's Subversion protocol emulation.
105166

167+
<a id="nestedblock--custom_property"></a>
168+
### Nested Schema for `custom_property`
169+
170+
Required:
171+
172+
- `name` (String) The name of the custom property.
173+
- `value` (List of String) The value(s) of the custom property. For single-value properties, provide a list with one element. For multi-select properties, provide multiple elements.
174+
175+
106176
<a id="nestedblock--pages"></a>
107177
### Nested Schema for `pages`
108178

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# GitHub Organization Custom Property
2+
3+
This example demonstrates how to create and manage custom properties for a GitHub organization.
4+
5+
## Usage
6+
7+
```hcl
8+
resource "github_organization_custom_property" "environment" {
9+
name = "environment"
10+
value_type = "single_select"
11+
required = true
12+
default_value = "production"
13+
description = "Prod or dev environment"
14+
allowed_values = ["production", "development"]
15+
values_editable_by = "org_actors"
16+
}
17+
```
18+
19+
## Attributes
20+
21+
- `name` - (Required) Name of the custom property
22+
- `value_type` - (Required) Type of the value for the property. Can be one of: `single_select`, `multi_select`, `string`, `true_false`
23+
- `required` - (Optional) Whether the property is required. Defaults to `false`
24+
- `default_value` - (Optional) Default value of the property
25+
- `description` - (Optional) A short description of the property
26+
- `allowed_values` - (Optional) List of allowed values for the property. Only applies when `value_type` is `single_select` or `multi_select`
27+
- `values_editable_by` - (Optional) Who can edit the values of the property. Can be one of: `org_actors`, `org_and_repo_actors`. Defaults to `org_actors`
28+
29+
## Additional Examples
30+
31+
### Multi-select property
32+
33+
```hcl
34+
resource "github_organization_custom_property" "tags" {
35+
name = "tags"
36+
value_type = "multi_select"
37+
required = false
38+
description = "Project tags"
39+
allowed_values = ["frontend", "backend", "database", "api"]
40+
values_editable_by = "org_and_repo_actors"
41+
}
42+
```
43+
44+
### String property
45+
46+
```hcl
47+
resource "github_organization_custom_property" "owner" {
48+
name = "owner"
49+
value_type = "string"
50+
required = false
51+
description = "Repository owner"
52+
values_editable_by = "org_actors"
53+
}
54+
```
55+
56+
### True/False property
57+
58+
```hcl
59+
resource "github_organization_custom_property" "archived" {
60+
name = "archived"
61+
value_type = "true_false"
62+
required = false
63+
description = "Is this repository archived"
64+
values_editable_by = "org_actors"
65+
}
66+
```
67+
68+
## Notes
69+
70+
- Custom properties are defined at the organization level and can be applied to repositories within the organization
71+
- When using `single_select` or `multi_select`, the `allowed_values` field is required
72+
- The `name` and `value_type` fields cannot be changed after creation (they are ForceNew)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This example matches the user's requested format with native HCL lists
2+
resource "github_repository" "example" {
3+
name = "example"
4+
description = "My awesome codebase"
5+
6+
custom_property {
7+
name = "foo"
8+
value = ["bar"]
9+
}
10+
11+
custom_property {
12+
name = "boolean"
13+
value = ["false"]
14+
}
15+
16+
custom_property {
17+
name = "multiselect"
18+
value = ["goo", "zoo"]
19+
}
20+
21+
custom_property {
22+
name = "singleselect"
23+
value = ["acme"]
24+
}
25+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This example demonstrates collaborative management of repository custom properties.
2+
# It assumes the organization already defines the referenced custom properties.
3+
4+
resource "github_repository" "example" {
5+
name = "example-shared-custom-props"
6+
description = "Repository with collaboratively managed custom properties"
7+
8+
exclusive_custom_properties = false
9+
10+
custom_property {
11+
name = "deployment-environment"
12+
value = ["production"]
13+
}
14+
}
15+
16+
resource "github_repository_custom_property" "compliance" {
17+
repository = github_repository.example.name
18+
property_name = "compliance-tier"
19+
property_type = "string"
20+
property_value = ["regulated"]
21+
}

0 commit comments

Comments
 (0)