@@ -85,11 +85,28 @@ func resourceTFETeamOrganizationMembersRead(d *schema.ResourceData, meta interfa
8585 return fmt .Errorf ("Error reading organization memberships from team %s: %w" , d .Id (), err )
8686 }
8787
88+ log .Printf ("[DEBUG] Read users from team: %s" , d .Id ())
89+ users , err := config .Client .TeamMembers .ListUsers (ctx , d .Id ())
90+ if err != nil {
91+ if errors .Is (err , tfe .ErrResourceNotFound ) {
92+ log .Printf ("[DEBUG] Users for team %s no longer exist" , d .Id ())
93+ return nil
94+ }
95+ return fmt .Errorf ("Error reading users from team %s: %w" , d .Id (), err )
96+ }
97+
98+ nonServiceAccountUsers := make (map [string ]interface {})
99+ for _ , user := range users {
100+ if ! user .IsServiceAccount {
101+ nonServiceAccountUsers [user .ID ] = nil
102+ }
103+ }
104+
88105 // Get all organization memberships and add them to object
89106 var organizationMembershipIDs []interface {}
90107 for _ , membership := range organizationMemberships {
91108 // Service accounts should not be managed by this resource
92- if ! membership .User .IsServiceAccount {
109+ if _ , ok := nonServiceAccountUsers [ membership .User .ID ]; ok {
93110 organizationMembershipIDs = append (organizationMembershipIDs , membership .ID )
94111 }
95112 }
0 commit comments