-
Notifications
You must be signed in to change notification settings - Fork 147
/
data_source_organization_membership.go
55 lines (44 loc) · 1.24 KB
/
data_source_organization_membership.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package tfe
import (
"context"
"fmt"
"github.com/hashicorp/go-tfe"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceTFEOrganizationMembership() *schema.Resource {
return &schema.Resource{
Read: dataSourceTFEOrganizationMembershipRead,
Schema: map[string]*schema.Schema{
"email": {
Type: schema.TypeString,
Optional: true,
},
"username": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"organization": {
Type: schema.TypeString,
Required: true,
},
"user_id": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceTFEOrganizationMembershipRead(d *schema.ResourceData, meta interface{}) error {
tfeClient := meta.(*tfe.Client)
// Get the user email and organization.
email := d.Get("email").(string)
username := d.Get("username").(string)
organization := d.Get("organization").(string)
orgMember, err := fetchOrganizationMemberByNameOrEmail(context.Background(), tfeClient, organization, username, email)
if err != nil {
return fmt.Errorf("Could not find organization membership for organization %s: %w", organization, err)
}
d.SetId(orgMember.ID)
return resourceTFEOrganizationMembershipRead(d, meta)
}