|
| 1 | +package deploygate |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "log" |
| 6 | + |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 8 | + go_deploygate "github.com/recruit-mp/go-deploygate" |
| 9 | +) |
| 10 | + |
| 11 | +func dataSourceOrganizationMember() *schema.Resource { |
| 12 | + return &schema.Resource{ |
| 13 | + Read: dataSourceOrganizationMemberRead, |
| 14 | + |
| 15 | + Schema: map[string]*schema.Schema{ |
| 16 | + "organization": { |
| 17 | + Type: schema.TypeString, |
| 18 | + Required: true, |
| 19 | + }, |
| 20 | + "members": { |
| 21 | + Type: schema.TypeSet, |
| 22 | + Computed: true, |
| 23 | + Elem: &schema.Resource{ |
| 24 | + Schema: map[string]*schema.Schema{ |
| 25 | + "type": { |
| 26 | + Type: schema.TypeString, |
| 27 | + Optional: true, |
| 28 | + }, |
| 29 | + "name": { |
| 30 | + Type: schema.TypeString, |
| 31 | + Optional: true, |
| 32 | + }, |
| 33 | + "url": { |
| 34 | + Type: schema.TypeString, |
| 35 | + Optional: true, |
| 36 | + }, |
| 37 | + "icon_url": { |
| 38 | + Type: schema.TypeString, |
| 39 | + Optional: true, |
| 40 | + }, |
| 41 | + "inviting": { |
| 42 | + Type: schema.TypeBool, |
| 43 | + Optional: true, |
| 44 | + }, |
| 45 | + }, |
| 46 | + }, |
| 47 | + }, |
| 48 | + }, |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +func dataSourceOrganizationMemberRead(d *schema.ResourceData, meta interface{}) error { |
| 53 | + client := meta.(*Client).client |
| 54 | + |
| 55 | + organization := d.Get("organization").(string) |
| 56 | + |
| 57 | + log.Printf("[DEBUG] dataSourceOrganizationMemberRead: %s", organization) |
| 58 | + |
| 59 | + g := &go_deploygate.GetOrganizationMemberInput{ |
| 60 | + OrganizationName: organization, |
| 61 | + } |
| 62 | + |
| 63 | + om, err := client.GetOrganizationMember(g) |
| 64 | + |
| 65 | + if err != nil { |
| 66 | + return err |
| 67 | + } |
| 68 | + |
| 69 | + rs := om |
| 70 | + |
| 71 | + d.SetId(fmt.Sprintf("%s", organization)) |
| 72 | + d.Set("members", rs.Members) |
| 73 | + |
| 74 | + return nil |
| 75 | +} |
0 commit comments