Skip to content

Commit

Permalink
only read members if member block defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Taimoor Ahmad committed Nov 29, 2023
1 parent ce26fff commit d87de6b
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions opslevel/resource_opslevel_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,24 @@ func resourceTeamRead(d *schema.ResourceData, client *opslevel.Client) error {
if err := d.Set("aliases", aliases); err != nil {
return err
}
members := collectMembersFromTeam(resource)
memberOutput := []map[string]interface{}{}
for _, m := range members {
mOutput := make(map[string]interface{})
mOutput["email"] = m.User.Email
mOutput["role"] = m.Role
memberOutput = append(memberOutput, mOutput)
}
if err := d.Set("member", memberOutput); err != nil {
return err

// only read members if it was set before in the configuration
// some customers may not have any member {} blocks defined
// in their config, and they cannot use terraform to manage
// teams because of it without either adding the members into
// the config or unassigning all the members (unwanted)
if members, ok := d.GetOk("member"); members != nil || ok {
members := collectMembersFromTeam(resource)
memberOutput := []map[string]interface{}{}
for _, m := range members {
mOutput := make(map[string]interface{})
mOutput["email"] = m.User.Email
mOutput["role"] = m.Role
memberOutput = append(memberOutput, mOutput)

Check warning on line 267 in opslevel/resource_opslevel_team.go

View check run for this annotation

Codecov / codecov/patch

opslevel/resource_opslevel_team.go#L260-L267

Added lines #L260 - L267 were not covered by tests
}
if err := d.Set("member", memberOutput); err != nil {
return err

Check warning on line 270 in opslevel/resource_opslevel_team.go

View check run for this annotation

Codecov / codecov/patch

opslevel/resource_opslevel_team.go#L269-L270

Added lines #L269 - L270 were not covered by tests
}
}

return nil
Expand Down

0 comments on commit d87de6b

Please sign in to comment.