Skip to content

Commit b396420

Browse files
author
Cristina Sánchez Sánchez
committed
CheckDestroy
1 parent 072a4b2 commit b396420

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

internal/service/clouduserprojectassignment/resource_test.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,11 @@ func checkDestroy(s *terraform.State) error {
104104
}
105105

106106
userID := r.Primary.Attributes["user_id"]
107-
username := r.Primary.Attributes["username"]
108107
projectID := r.Primary.Attributes["project_id"]
109-
conn := acc.ConnV2()
110108

111-
userListResp, _, err := conn.MongoDBCloudUsersApi.ListProjectUsers(context.Background(), projectID).Execute()
112-
if err != nil {
113-
continue
114-
}
115-
116-
if userListResp != nil {
117-
results := userListResp.GetResults()
118-
for i := range results {
119-
if userID != "" && results[i].GetId() == userID {
120-
return fmt.Errorf("cloud user project assignment for user (%s) in project (%s) still exists", r.Primary.Attributes["username"], projectID)
121-
}
122-
if username != "" && results[i].GetUsername() == username {
123-
return fmt.Errorf("cloud user project assignment for user (%s) in project (%s) still exists", r.Primary.Attributes["username"], projectID)
124-
}
125-
}
109+
_, _, err := acc.ConnV2().MongoDBCloudUsersApi.GetProjectUser(context.Background(), projectID, userID).Execute()
110+
if err == nil {
111+
return fmt.Errorf("cloud user project assignment for user (%s) in project (%s) still exists", userID, projectID)
126112
}
127113
}
128114
return nil

0 commit comments

Comments
 (0)