diff --git a/google/common_operation.go b/google/common_operation.go index 099fcbaf8..dbd8dc81b 100644 --- a/google/common_operation.go +++ b/google/common_operation.go @@ -3,12 +3,10 @@ package google import ( "fmt" "log" - "net/url" "time" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" cloudresourcemanager "google.golang.org/api/cloudresourcemanager/v1" - "google.golang.org/api/googleapi" ) type Waiter interface { @@ -103,14 +101,11 @@ func CommonRefreshFunc(w Waiter) resource.StateRefreshFunc { return func() (interface{}, string, error) { op, err := w.QueryOp() if err != nil { - for _, e := range getAllTypes(err, &googleapi.Error{}, &url.Error{}) { - // Retry 404 when getting operation (not resource state) - if isRetryableError(e, isNotFoundRetryableError("GET operation")) { - log.Printf("[DEBUG] Dismissed error on GET of operation '%v' retryable: %s", w.OpName(), err) - return nil, "done: false", nil - } + // Retry 404 when getting operation (not resource state) + if isRetryableError(err, isNotFoundRetryableError("GET operation")) { + log.Printf("[DEBUG] Dismissed retryable error on GET operation %q: %s", w.OpName(), err) + return nil, "done: false", nil } - return nil, "", fmt.Errorf("error while retrieving operation: %s", err) } diff --git a/google/retry_utils.go b/google/retry_utils.go index d6387ede3..23aefb11f 100644 --- a/google/retry_utils.go +++ b/google/retry_utils.go @@ -2,12 +2,10 @@ package google import ( "log" - "net/url" "time" "github.com/hashicorp/errwrap" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "google.golang.org/api/googleapi" ) func retry(retryFunc func() error) error { @@ -31,17 +29,6 @@ func retryTimeDuration(retryFunc func() error, duration time.Duration, errorRetr }) } -func getAllTypes(err error, args ...interface{}) []error { - var result []error - for _, v := range args { - subResult := errwrap.GetAllType(err, v) - if subResult != nil { - result = append(result, subResult...) - } - } - return result -} - func isRetryableError(topErr error, customPredicates ...RetryErrorPredicateFunc) bool { retryPredicates := append( // Global error retry predicates are registered in this default list. @@ -49,13 +36,15 @@ func isRetryableError(topErr error, customPredicates ...RetryErrorPredicateFunc) customPredicates...) // Check all wrapped errors for a retryable error status. - for _, err := range getAllTypes(topErr, &googleapi.Error{}, &url.Error{}) { + isRetryable := false + errwrap.Walk(topErr, func(werr error) { for _, pred := range retryPredicates { - if retry, reason := pred(err); retry { - log.Printf("[DEBUG] Dismissed an error as retryable. %s - %s", reason, err) - return true + if predRetry, predReason := pred(werr); predRetry { + log.Printf("[DEBUG] Dismissed an error as retryable. %s - %s", predReason, werr) + isRetryable = true + return } } - } - return false + }) + return isRetryable }