diff --git a/codefresh/resource_project.go b/codefresh/resource_project.go index 2212094..2ad4d42 100644 --- a/codefresh/resource_project.go +++ b/codefresh/resource_project.go @@ -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" ) @@ -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 } diff --git a/go.mod b/go.mod index d3f90f2..330ef7b 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 030134c..7e713f9 100644 --- a/go.sum +++ b/go.sum @@ -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=