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