Skip to content

Commit 3432109

Browse files
author
Ali Reza Yahya
committed
draft: data org custom properties
1 parent 5bc50c9 commit 3432109

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package github
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8+
)
9+
10+
func dataSourceGithubOrganizationCustomProperties() *schema.Resource {
11+
return &schema.Resource{
12+
Read: dataSourceGithubOrganizationCustomPropertiesRead,
13+
14+
Schema: map[string]*schema.Schema{
15+
"property_name": {
16+
Type: schema.TypeString,
17+
Required: true,
18+
},
19+
"value_type": {
20+
Type: schema.TypeString,
21+
Required: true,
22+
},
23+
"required": {
24+
Type: schema.TypeBool,
25+
Required: true,
26+
},
27+
"default_value": {
28+
Type: schema.TypeString,
29+
Optional: true,
30+
Computed: true,
31+
},
32+
"description": {
33+
Type: schema.TypeString,
34+
Optional: true,
35+
Computed: true,
36+
},
37+
"allowed_values": {
38+
Type: schema.TypeList,
39+
Optional: true,
40+
Computed: true,
41+
Elem: &schema.Schema{Type: schema.TypeString},
42+
},
43+
},
44+
}
45+
}
46+
47+
func dataSourceGithubOrganizationCustomPropertiesRead(d *schema.ResourceData, meta interface{}) error {
48+
client := meta.(*Owner).v3client
49+
ctx := context.Background()
50+
orgName := meta.(*Owner).name
51+
52+
err := checkOrganization(meta)
53+
if err != nil {
54+
return err
55+
}
56+
57+
propertyAttributes, _, err := client.Organizations.GetCustomProperty(ctx, orgName, d.Get("property_name").(string))
58+
if err != nil {
59+
return fmt.Errorf("error querying GitHub custom properties %s: %s", orgName, err)
60+
}
61+
62+
d.SetId("org-custom-properties")
63+
d.Set("allowed_values", propertyAttributes.AllowedValues)
64+
d.Set("default_value", propertyAttributes.DefaultValue)
65+
d.Set("description", propertyAttributes.Description)
66+
d.Set("property_name", propertyAttributes.PropertyName)
67+
d.Set("required", propertyAttributes.Required)
68+
d.Set("value_type", propertyAttributes.ValueType)
69+
70+
return nil
71+
}

github/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ func Provider() terraform.ResourceProvider {
202202
"github_membership": dataSourceGithubMembership(),
203203
"github_organization": dataSourceGithubOrganization(),
204204
"github_organization_custom_role": dataSourceGithubOrganizationCustomRole(),
205+
"github_organization_custom_properties": dataSourceGithubOrganizationCustomProperties(),
205206
"github_organization_external_identities": dataSourceGithubOrganizationExternalIdentities(),
206207
"github_organization_ip_allow_list": dataSourceGithubOrganizationIpAllowList(),
207208
"github_organization_team_sync_groups": dataSourceGithubOrganizationTeamSyncGroups(),

0 commit comments

Comments
 (0)