|
| 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 | +} |
0 commit comments