Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding retry logic to deleting schedule,team_membership and user #258

Merged
merged 1 commit into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions pagerduty/resource_pagerduty_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,20 @@ func resourcePagerDutyScheduleDelete(d *schema.ResourceData, meta interface{}) e

log.Printf("[INFO] Deleting PagerDuty schedule: %s", d.Id())

if _, err := client.Schedules.Delete(d.Id()); err != nil {
return err
// Retrying to give other resources (such as escalation policies) to delete
retryErr := resource.Retry(2*time.Minute, func() *resource.RetryError {
if _, err := client.Schedules.Delete(d.Id()); err != nil {
if isErrCode(err, 400) {
return resource.RetryableError(err)
}

return resource.NonRetryableError(err)
}
return nil
})
if retryErr != nil {
time.Sleep(2 * time.Second)
return retryErr
}

d.SetId("")
Expand Down
16 changes: 14 additions & 2 deletions pagerduty/resource_pagerduty_team_membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,20 @@ func resourcePagerDutyTeamMembershipDelete(d *schema.ResourceData, meta interfac

log.Printf("[DEBUG] Removing user: %s from team: %s", userID, teamID)

if _, err := client.Teams.RemoveUser(teamID, userID); err != nil {
return err
// Retrying to give other resources (such as escalation policies) to delete
retryErr := resource.Retry(2*time.Minute, func() *resource.RetryError {
if _, err := client.Teams.RemoveUser(teamID, userID); err != nil {
if isErrCode(err, 400) {
return resource.RetryableError(err)
}

return resource.NonRetryableError(err)
}
return nil
})
if retryErr != nil {
time.Sleep(2 * time.Second)
return retryErr
}

d.SetId("")
Expand Down
16 changes: 14 additions & 2 deletions pagerduty/resource_pagerduty_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,20 @@ func resourcePagerDutyUserDelete(d *schema.ResourceData, meta interface{}) error

log.Printf("[INFO] Deleting PagerDuty user %s", d.Id())

if _, err := client.Users.Delete(d.Id()); err != nil {
return err
// Retrying to give other resources (such as escalation policies) to delete
retryErr := resource.Retry(2*time.Minute, func() *resource.RetryError {
if _, err := client.Users.Delete(d.Id()); err != nil {
if isErrCode(err, 400) {
return resource.RetryableError(err)
}

return resource.NonRetryableError(err)
}
return nil
})
if retryErr != nil {
time.Sleep(2 * time.Second)
return retryErr
}

d.SetId("")
Expand Down