Skip to content

Commit d5be511

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

File tree

2 files changed

+79
-0
lines changed

2 files changed

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

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)