Skip to content

Commit

Permalink
change schema...
Browse files Browse the repository at this point in the history
  • Loading branch information
Taimoor Ahmad committed Nov 8, 2023
1 parent 97bac35 commit dc69f68
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions opslevel/resource_opslevel_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,26 @@ func resourceTeam() *schema.Resource {
ForceNew: false,
Optional: true,
},
"member": {
Type: schema.TypeSet,
"members": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"email": {
Type: schema.TypeString,
Required: true,
},
"role": {
Type: schema.TypeString,
Required: false,
"member": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"email": {
Type: schema.TypeString,
Required: true,
},
"role": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
},
},
Expand Down Expand Up @@ -135,44 +144,40 @@ func memberInArray(member map[string]interface{}, array []map[string]interface{}
return true
}
}

return false
}

func reconcileTeamMembership(d *schema.ResourceData, team *opslevel.Team, client *opslevel.Client) error {
expectedMembers := d.Get("member").([]map[string]interface{})
expectedMembers := d.Get("members").([]map[string]interface{})
existingMembers := collectMembersFromTeam(team)

membersToRemove := []map[string]interface{}{}
membersToAdd := []map[string]interface{}{}

for _, existingMember := range existingMembers {
if memberInArray(existingMember, expectedMembers) {
continue
if !memberInArray(existingMember, expectedMembers) {
membersToRemove = append(membersToRemove, existingMember)
}
membersToRemove = append(membersToRemove, existingMember)
}

for _, expectedMember := range expectedMembers {
if memberInArray(expectedMember, existingMembers) {
continue
if !memberInArray(expectedMember, existingMembers) {
membersToAdd = append(membersToAdd, expectedMember)
}
membersToAdd = append(membersToAdd, expectedMember)
}

if len(membersToAdd) != 0 {
_, err := client.AddMembers(&team.TeamId, membersToAdd)
if len(membersToRemove) > 0 {
_, err := client.RemoveMembers(&team.TeamId, membersToRemove)

Check failure on line 169 in opslevel/resource_opslevel_team.go

View workflow job for this annotation

GitHub Actions / test

cannot use membersToRemove (variable of type []map[string]interface{}) as []string value in argument to client.RemoveMembers
if err != nil {
return err
}
}

if len(membersToRemove) != 0 {
_, err := client.RemoveMembers(&team.TeamId, membersToRemove)
if len(membersToAdd) > 0 {
_, err := client.AddMembers(&team.TeamId, membersToAdd)

Check failure on line 175 in opslevel/resource_opslevel_team.go

View workflow job for this annotation

GitHub Actions / test

cannot use membersToAdd (variable of type []map[string]interface{}) as []string value in argument to client.AddMembers
if err != nil {
return err
}
}

return nil
}

Expand Down

0 comments on commit dc69f68

Please sign in to comment.