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 3011363
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
71 changes: 71 additions & 0 deletions github/data_source_github_organization_custom_properties.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package github

import (
"context"
"fmt"

"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,
Optional: true,
},
"required": {
Type: schema.TypeBool,
Optional: 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},
},
},
}
}

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
}

propertyAttributes, _, err := client.Organizations.GetCustomProperty(ctx, orgName, d.Get("property_name").(string))
if err != nil {
return fmt.Errorf("error querying GitHub custom properties %s: %s", orgName, err)
}

d.SetId("org-custom-properties")
d.Set("allowed_values", propertyAttributes.AllowedValues)
d.Set("default_value", propertyAttributes.DefaultValue)
d.Set("description", propertyAttributes.Description)
d.Set("property_name", propertyAttributes.PropertyName)
d.Set("required", propertyAttributes.Required)
d.Set("value_type", propertyAttributes.ValueType)

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 3011363

Please sign in to comment.