Skip to content

Commit

Permalink
draft: data org custom properties
Browse files Browse the repository at this point in the history
  • Loading branch information
alileza committed Jan 16, 2024
1 parent 5bc50c9 commit d5be511
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
78 changes: 78 additions & 0 deletions github/data_source_github_organization_custom_properties.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package github

import (
"context"
"fmt"

"github.com/google/go-github/v57/github"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func dataSourceGithubOrganizationCustomProperties() *schema.Resource {
return &schema.Resource{
Read: dataSourceGithubOrganizationCustomPropertiesRead,

Schema: map[string]*schema.Schema{
"property_name": {
Type: schema.TypeString,
Required: true,
},
"value_type": {
Type: schema.TypeString,
Required: true,
},
"required": {
Type: schema.TypeBool,
Required: true,
},
"default_value": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"allowed_values": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"values_editable_by": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}

func dataSourceGithubOrganizationCustomPropertiesRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Owner).v3client
ctx := context.Background()
orgName := meta.(*Owner).name

err := checkOrganization(meta)
if err != nil {
return err
}

propertyList, _, err := client.Organizations.ListCustomPropertyValues(ctx, orgName, nil)
if err != nil {
return fmt.Errorf("error querying GitHub custom properties %s: %s", orgName, err)
}

var properties []*github.RepoCustomPropertyValue
for _, p := range propertyList {
properties = append(properties, p)
}

d.SetId("org-custom-properties")
d.Set("custom-properties", properties)

return nil
}
1 change: 1 addition & 0 deletions github/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func Provider() terraform.ResourceProvider {
"github_membership": dataSourceGithubMembership(),
"github_organization": dataSourceGithubOrganization(),
"github_organization_custom_role": dataSourceGithubOrganizationCustomRole(),
"github_organization_custom_properties": dataSourceGithubOrganizationCustomProperties(),
"github_organization_external_identities": dataSourceGithubOrganizationExternalIdentities(),
"github_organization_ip_allow_list": dataSourceGithubOrganizationIpAllowList(),
"github_organization_team_sync_groups": dataSourceGithubOrganizationTeamSyncGroups(),
Expand Down

0 comments on commit d5be511

Please sign in to comment.