Skip to content

Commit 79b4ec9

Browse files
committed
Add ValuesEditableBy support to github_organization_custom_properties
1 parent 78196d6 commit 79b4ec9

5 files changed

+89
-3
lines changed

github/data_source_github_organization_custom_properties.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ func dataSourceGithubOrganizationCustomProperties() *schema.Resource {
4040
Computed: true,
4141
Elem: &schema.Schema{Type: schema.TypeString},
4242
},
43+
"values_editable_by": {
44+
Type: schema.TypeString,
45+
Optional: true,
46+
Computed: true,
47+
},
4348
},
4449
}
4550
}
@@ -66,6 +71,7 @@ func dataSourceGithubOrganizationCustomPropertiesRead(d *schema.ResourceData, me
6671
_ = d.Set("property_name", propertyAttributes.PropertyName)
6772
_ = d.Set("required", propertyAttributes.Required)
6873
_ = d.Set("value_type", propertyAttributes.ValueType)
74+
_ = d.Set("values_editable_by", propertyAttributes.ValuesEditableBy)
6975

7076
return nil
7177
}

github/resource_github_organization_custom_properties.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ func resourceGithubOrganizationCustomProperties() *schema.Resource {
5959
Computed: true,
6060
Elem: &schema.Schema{Type: schema.TypeString},
6161
},
62+
"values_editable_by": {
63+
Description: "Who can edit the values of the custom property. Can be one of 'org_actors' or 'org_and_repo_actors'. If not specified, the default is 'org_actors' (only organization owners can edit values)",
64+
Type: schema.TypeString,
65+
Optional: true,
66+
Computed: true,
67+
},
6268
},
6369
}
6470
}
@@ -79,14 +85,22 @@ func resourceGithubCustomPropertiesCreate(d *schema.ResourceData, meta any) erro
7985
allowedValuesString = append(allowedValuesString, v.(string))
8086
}
8187

82-
customProperty, _, err := client.Organizations.CreateOrUpdateCustomProperty(ctx, ownerName, d.Get("property_name").(string), &github.CustomProperty{
88+
customProperty := &github.CustomProperty{
8389
PropertyName: &propertyName,
8490
ValueType: valueType,
8591
Required: &required,
8692
DefaultValue: &defaultValue,
8793
Description: &description,
8894
AllowedValues: allowedValuesString,
89-
})
95+
}
96+
97+
// Set ValuesEditableBy if provided
98+
if valuesEditableBy, ok := d.GetOk("values_editable_by"); ok {
99+
valuesEditableByStr := valuesEditableBy.(string)
100+
customProperty.ValuesEditableBy = &valuesEditableByStr
101+
}
102+
103+
customProperty, _, err := client.Organizations.CreateOrUpdateCustomProperty(ctx, ownerName, d.Get("property_name").(string), customProperty)
90104
if err != nil {
91105
return err
92106
}
@@ -112,6 +126,7 @@ func resourceGithubCustomPropertiesRead(d *schema.ResourceData, meta any) error
112126
_ = d.Set("property_name", customProperty.PropertyName)
113127
_ = d.Set("required", customProperty.Required)
114128
_ = d.Set("value_type", customProperty.ValueType)
129+
_ = d.Set("values_editable_by", customProperty.ValuesEditableBy)
115130

116131
return nil
117132
}

github/resource_github_organization_custom_properties_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,51 @@ func TestAccGithubOrganizationCustomProperties(t *testing.T) {
151151
testCase(t, organization)
152152
})
153153
})
154+
155+
t.Run("creates custom property with values_editable_by without error", func(t *testing.T) {
156+
config := `
157+
resource "github_organization_custom_properties" "test" {
158+
property_name = "TestValuesEditableBy"
159+
value_type = "string"
160+
required = false
161+
description = "Test property for values_editable_by"
162+
values_editable_by = "org_and_repo_actors"
163+
}`
164+
165+
check := resource.ComposeTestCheckFunc(
166+
resource.TestCheckResourceAttr(
167+
"github_organization_custom_properties.test",
168+
"property_name", "TestValuesEditableBy",
169+
),
170+
resource.TestCheckResourceAttr(
171+
"github_organization_custom_properties.test",
172+
"values_editable_by", "org_and_repo_actors",
173+
),
174+
)
175+
176+
testCase := func(t *testing.T, mode string) {
177+
resource.Test(t, resource.TestCase{
178+
PreCheck: func() { skipUnlessMode(t, mode) },
179+
Providers: testAccProviders,
180+
Steps: []resource.TestStep{
181+
{
182+
Config: config,
183+
Check: check,
184+
},
185+
},
186+
})
187+
}
188+
189+
t.Run("with an anonymous account", func(t *testing.T) {
190+
t.Skip("anonymous account not supported for this operation")
191+
})
192+
193+
t.Run("with an individual account", func(t *testing.T) {
194+
t.Skip("individual account not supported for this operation")
195+
})
196+
197+
t.Run("with an organization account", func(t *testing.T) {
198+
testCase(t, organization)
199+
})
200+
})
154201
}

website/docs/d/organization_custom_properties.html.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ The following arguments are supported:
3535

3636
* `default_value` - The default value of the custom property.
3737

38-
* `allowed_values` - List of allowed values for the custom property. Only populated when `value_type` is `single_select` or `multi_select`.
38+
* `allowed_values` - List of allowed values for the custom property. Only populated when `value_type` is `single_select` or `multi_select`.
39+
40+
* `values_editable_by` - Who can edit the values of the custom property. Can be one of `org_actors` or `org_and_repo_actors`.

website/docs/r/organization_custom_properties.html.markdown

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ resource "github_organization_custom_properties" "environment" {
2828
}
2929
```
3030

31+
## Example Usage - Allow Repository Actors to Edit
32+
33+
This example shows how to allow repository administrators to edit the property values:
34+
35+
```hcl
36+
resource "github_organization_custom_properties" "team_contact" {
37+
property_name = "team_contact"
38+
value_type = "string"
39+
required = false
40+
description = "Contact information for the team managing this repository"
41+
values_editable_by = "org_and_repo_actors"
42+
}
43+
```
44+
3145
## Example Usage - Text Property
3246

3347
```hcl
@@ -67,6 +81,8 @@ The following arguments are supported:
6781

6882
* `allowed_values` - (Optional) List of allowed values for the custom property. Only applicable when `value_type` is `single_select` or `multi_select`.
6983

84+
* `values_editable_by` - (Optional) Who can edit the values of the custom property. Can be one of `org_actors` or `org_and_repo_actors`. When set to `org_actors` (the default), only organization owners can edit the property values on repositories. When set to `org_and_repo_actors`, both organization owners and repository administrators with the custom properties permission can edit the values.
85+
7086
## Attributes Reference
7187

7288
In addition to all arguments above, the following attributes are exported:

0 commit comments

Comments
 (0)