Skip to content

Commit

Permalink
Introduce retry logic for project delete to address eventual consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
sandrogattuso committed Apr 16, 2021
1 parent f8c9f7f commit 515053e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
17 changes: 15 additions & 2 deletions codefresh/resource_project.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package codefresh

import (
"log"
"time"

"github.com/cenkalti/backoff"
cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -90,8 +94,17 @@ func resourceProjectUpdate(d *schema.ResourceData, meta interface{}) error {

func resourceProjectDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cfClient.Client)

err := client.DeleteProject(d.Id())
// Adding a Retry backoff to address eventual consistency for the API
expBackoff := backoff.NewExponentialBackOff()
expBackoff.MaxElapsedTime = 2 * time.Second
err := backoff.Retry(
func() error {
err := client.DeleteProject(d.Id())
if err != nil {
log.Printf("Unable to destroy Project due to error %v", err)
}
return err
}, expBackoff)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ require (
github.com/aws/aws-sdk-go v1.30.12 // indirect
github.com/bflad/tfproviderdocs v0.6.0
github.com/bflad/tfproviderlint v0.14.0
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/cenkalti/backoff/v4 v4.1.0
github.com/client9/misspell v0.3.4
github.com/ghodss/yaml v1.0.0
github.com/golangci/golangci-lint v1.27.0
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ github.com/bmatcuk/doublestar v1.2.1 h1:eetYiv8DDYOZcBADY+pRvRytf3Dlz1FhnpvL2FsC
github.com/bmatcuk/doublestar v1.2.1/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE=
github.com/bombsimon/wsl/v3 v3.0.0 h1:w9f49xQatuaeTJFaNP4SpiWSR5vfT6IstPtM62JjcqA=
github.com/bombsimon/wsl/v3 v3.0.0/go.mod h1:st10JtZYLE4D5sC7b8xV4zTKZwAQjCH/Hy2Pm1FNZIc=
github.com/cenkalti/backoff v1.1.0 h1:QnvVp8ikKCDWOsFheytRCoYWYPO/ObCTBGxT19Hc+yE=
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/cenkalti/backoff/v4 v4.1.0 h1:c8LkOFQTzuO0WBM/ae5HdGQuZPfPxp7lqBRwQRm4fSc=
github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
Expand Down

0 comments on commit 515053e

Please sign in to comment.