Skip to content

Commit c327081

Browse files
committed
fix: Refactor repository custom property
Signed-off-by: Steve Hipwell <steve.hipwell@gmail.com>
1 parent e286cb0 commit c327081

10 files changed

Lines changed: 480 additions & 87 deletions

ARCHITECTURE.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ func resourceGithubExample() *schema.Resource {
178178
StateContext: resourceGithubExampleImport,
179179
},
180180

181-
// Include SchemaVersion and StateUpgraders if state migrations exist
181+
// Only if required.
182+
CustomizeDiff: diffExample,
183+
184+
// Include SchemaVersion and StateUpgraders if state migrations exist.
182185
SchemaVersion: 1,
183186
StateUpgraders: []schema.StateUpgrader{
184187
{
@@ -188,8 +191,10 @@ func resourceGithubExample() *schema.Resource {
188191
},
189192
},
190193

194+
Description: "Manages an example GitHub resource.",
195+
191196
Schema: map[string]*schema.Schema{
192-
// Schema definition
197+
// Schema definition.
193198
},
194199
}
195200
}

docs/resources/repository_custom_property.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
---
22
page_title: "github_repository_custom_property (Resource) - GitHub"
3+
subcategory: ""
34
description: |-
4-
Creates and a specific custom property for a GitHub repository
5+
Resource to manage GitHub repository custom properties.
56
---
67

78
# github_repository_custom_property (Resource)
89

9-
This resource allows you to create and manage a specific custom property for a GitHub repository.
10+
Resource to manage GitHub repository custom properties.
11+
For more information, see the [GitHub API documentation](https://docs.github.com/rest/metadata/custom-properties#create-or-update-repository-custom-property).
1012

1113
## Example Usage
1214

13-
> Note that this assumes there already is a custom property defined on the org level called `my-cool-property` of type `string`
14-
1515
```terraform
16+
# NOTE: This assumes there already is a custom property defined on the org level called `my-cool-property` of type `string`
17+
1618
resource "github_repository" "example" {
1719
name = "example"
1820
description = "My awesome codebase"
1921
}
22+
2023
resource "github_repository_custom_property" "string" {
2124
repository = github_repository.example.name
2225
property_name = "my-cool-property"
@@ -25,21 +28,35 @@ resource "github_repository_custom_property" "string" {
2528
}
2629
```
2730

28-
## Argument Reference
31+
<!-- schema generated by tfplugindocs -->
32+
## Schema
2933

30-
The following arguments are supported:
34+
### Required
3135

32-
- `repository` - (Required) The repository of the environment.
36+
- `property_name` (String) Name of the custom property.
37+
- `property_type` (String) Type of the custom property. Valid values are `string`, `single_select`, `multi_select`, `true_false`, and `url`.
38+
- `property_value` (Set of String) Value of the custom property. For `string`, `single_select`, `true_false`, and `url` property types, this should be a single value. For `multi_select` property types, this can be multiple values.
39+
- `repository` (String) Name of the repository.
3340

34-
- `property_type` - (Required) Type of the custom property. Can be one of `single_select`, `multi_select`, `string`, or `true_false`
41+
### Read-Only
3542

36-
- `property_name` - (Required) Name of the custom property. Note that a pre-requisiste for this resource is that a custom property of this name has already been defined on the organization level
37-
38-
- `property_value` - (Required) Value of the custom property in the form of an array. Properties of type `single_select`, `string`, and `true_false` are represented as a string array of length 1
43+
- `id` (String) The ID of this resource.
44+
- `repository_id` (Number) ID of the repository.
3945

4046
## Import
4147

42-
GitHub Repository Custom Property can be imported using an ID made up of a combination of the names of the organization, repository, custom property separated by a `:` character, e.g.
48+
Import is supported using the following syntax:
49+
50+
In Terraform v1.5.0 and later, the [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used with the `id` attribute, for example:
51+
52+
```terraform
53+
import {
54+
to = github_repository_custom_property.example
55+
id = "organization-name:repo-name:custom-property-name"
56+
}
57+
```
58+
59+
The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:
4360

4461
```shell
4562
terraform import github_repository_custom_property.example organization-name:repo-name:custom-property-name
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {
2+
to = github_repository_custom_property.example
3+
id = "organization-name:repo-name:custom-property-name"
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
terraform import github_repository_custom_property.example organization-name:repo-name:custom-property-name

examples/resources/repository_custom_property/example_1.tf renamed to examples/resources/github_repository_custom_property/resource_1.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
# NOTE: This assumes there already is a custom property defined on the org level called `my-cool-property` of type `string`
2+
13
resource "github_repository" "example" {
24
name = "example"
35
description = "My awesome codebase"
46
}
7+
58
resource "github_repository_custom_property" "string" {
69
repository = github_repository.example.name
710
property_name = "my-cool-property"

0 commit comments

Comments
 (0)