|
4 | 4 | "fmt"
|
5 | 5 | "log"
|
6 | 6 | "strconv"
|
| 7 | + "time" |
7 | 8 |
|
| 9 | + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" |
8 | 10 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
9 | 11 | gitlab "github.com/xanzy/go-gitlab"
|
10 | 12 | )
|
@@ -179,8 +181,28 @@ func resourceGitlabUserDelete(d *schema.ResourceData, meta interface{}) error {
|
179 | 181 |
|
180 | 182 | id, _ := strconv.Atoi(d.Id())
|
181 | 183 |
|
182 |
| - _, err := client.Users.DeleteUser(id) |
183 |
| - // Ignoring error due to some bug in library |
184 |
| - log.Printf("[DEBUG] Delete gitlab user %s", err) |
| 184 | + if _, err := client.Users.DeleteUser(id); err != nil { |
| 185 | + return err |
| 186 | + } |
| 187 | + |
| 188 | + stateConf := &resource.StateChangeConf{ |
| 189 | + Timeout: 5 * time.Minute, |
| 190 | + Target: []string{"Deleted"}, |
| 191 | + Refresh: func() (interface{}, string, error) { |
| 192 | + user, resp, err := client.Users.GetUser(id) |
| 193 | + if resp != nil && resp.StatusCode == 404 { |
| 194 | + return user, "Deleted", nil |
| 195 | + } |
| 196 | + if err != nil { |
| 197 | + return user, "Error", err |
| 198 | + } |
| 199 | + return user, "Deleting", nil |
| 200 | + }, |
| 201 | + } |
| 202 | + |
| 203 | + if _, err := stateConf.WaitForState(); err != nil { |
| 204 | + return fmt.Errorf("Could not finish deleting user %d: %w", id, err) |
| 205 | + } |
| 206 | + |
185 | 207 | return nil
|
186 | 208 | }
|
0 commit comments