Skip to content

Commit

Permalink
Add a logic to handle a case when roles can be changed back to the 'p…
Browse files Browse the repository at this point in the history
…ending state;

Increase timeout for deleting a role
  • Loading branch information
hdbpoc committed Oct 4, 2023
1 parent 663e73d commit a104827
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion provider/resource_rediscloud_acl_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,28 @@ func resourceRedisCloudAclRoleDelete(ctx context.Context, d *schema.ResourceData
return diag.FromErr(err)
}

// Every now and then the status of the role changes back to the 'pending' state after being fully created.
// The DELETE request will fail if the role is pending.
// This block queries the endpoint until the role is no longer in the 'pending' state.
err = retry.RetryContext(ctx, 5*time.Minute, func() *retry.RetryError {
role, err := api.client.Roles.Get(ctx, id)
if err != nil {
// This was an unexpected error
return retry.NonRetryableError(fmt.Errorf("error getting role: %s", err))
}
status := redis.StringValue(role.Status)
if status != roles.StatusPending {
// The role is ready for deletion
return nil
} else {
return retry.RetryableError(fmt.Errorf("can't delete the role %d in state %s", id, status))
}
})

if err != nil {
return diag.FromErr(err)
}

err = api.client.Roles.Delete(ctx, id)

if err != nil {
Expand All @@ -187,7 +209,7 @@ func resourceRedisCloudAclRoleDelete(ctx context.Context, d *schema.ResourceData
d.SetId("")

// Wait until it's really disappeared
err = retry.RetryContext(ctx, 5*time.Minute, func() *retry.RetryError {
err = retry.RetryContext(ctx, 10*time.Minute, func() *retry.RetryError {
role, err := api.client.Roles.Get(ctx, id)

if err != nil {
Expand Down

0 comments on commit a104827

Please sign in to comment.