Skip to content

Commit

Permalink
make userGroupMembershipImporter private, typos & wording
Browse files Browse the repository at this point in the history
  • Loading branch information
gypsydiver committed Jan 11, 2019
1 parent c41f696 commit 0764a06
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions jumpcloud/resource_user_group_membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ func resourceUserGroupMembership() *schema.Resource {
},
},
Importer: &schema.ResourceImporter{
State: UserGroupMembershipImporter,
State: userGroupMembershipImporter,
},
}
}

// We cannot use the regular importer as it calls the read function ONLY with the ID field being
// populated.- In our case, we need the group Id and user Is to do the read - But since our
// artificial resource ID is simply the combination of user ID group ID seperated by a'/' ,
// we can derive both vautes during our import process'
func UserGroupMembershipImporter(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
// populated.- In our case, we need the group ID and user ID to do the read - But since our
// artificial resource ID is simply the concatenation of user ID group ID seperated by a '/',
// we can derive both values during our import process
func userGroupMembershipImporter(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
s := strings.Split(d.Id(), "/")
d.Set("groupid", s[0])
d.Set("userid", s[1])
Expand Down Expand Up @@ -91,12 +91,13 @@ func resourceUserGroupMembershipRead(d *schema.ResourceData, m interface{}) erro
if err != nil {
return err
}

// The Userids are hidden in a super-complex construct, see
// https://github.com/TheJumpCloud/jcapi-go/blob/master/v2/docs/GraphConnection.md
for _, v := range graphconnect {
if v.To.Id == d.Get("userid") {
// Found - As we not have a JC-ID for the membership we simply store
// the combination of group ID and user ID as our membership ID
// the concatenation of group ID and user ID as our membership ID
d.SetId(d.Get("groupid").(string) + "/" + d.Get("userid").(string))
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion jumpcloud/resource_user_group_membership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestAccUserGroupMembership(t *testing.T) {
CheckDestroy: nil,
Steps: []resource.TestStep{
{
// The only reasonable step is to check if the useris is in the state
// The only reasonable step is to check if the user is in the state
// It will be deleted from the state in case the membership could not be
// established
Config: testAccUserGroupMembership(rName),
Expand Down

0 comments on commit 0764a06

Please sign in to comment.