Race condition error when recreating group service accounts

The gitlab_group_service_account resource is set to force recreate whenever any of the attributes are changed. However, this can result in the creation failing if the old version of the service account has not finished deleting.

For example, here we changed the value of the email and name attributes, but the username attribute remained the same:


│ Error: GitLab API error occurred

│   with module.service_accounts.gitlab_group_service_account.service_account["xxx"],
│   on .terraform/modules/service_accounts/service_account/gitlab_group_service_account.tf line 5, in resource "gitlab_group_service_account" "service_account":
│    5: resource "gitlab_group_service_account" "service_account" {

│ Unable to create service account: POST
│ https://gitlab.com/api/v4/groups/xxx/service_accounts: 400 {message:
│ 400 Bad request - Username has already been taken}

What do you think about putting wait+retry in the Delete function so it checks to see if the deletion has gone through before completing the destroy?