From 263f4ad8490a8c4ee39eb1773eced9e86a35f54c Mon Sep 17 00:00:00 2001 From: Dana Hoffman Date: Thu, 12 Sep 2019 10:19:50 -0700 Subject: [PATCH] retry on resourceNotReady (#2307) Merged PR #2307. --- build/terraform | 2 +- build/terraform-beta | 2 +- build/terraform-mapper | 2 +- third_party/terraform/utils/common_operation.go | 11 +++++++++++ third_party/terraform/utils/compute_operation.go | 11 +++++++++++ third_party/terraform/utils/container_operation.go | 4 ++++ third_party/terraform/utils/dataproc_job_operation.go | 4 ++++ third_party/terraform/utils/sqladmin_operation.go | 4 ++++ 8 files changed, 37 insertions(+), 3 deletions(-) diff --git a/build/terraform b/build/terraform index 60da6510e09c..65f26df0506d 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 60da6510e09c623943e5c50807f308244a592742 +Subproject commit 65f26df0506d77628d43303a8afe4f6b4a61ffb7 diff --git a/build/terraform-beta b/build/terraform-beta index 46f6df10e59f..1befeb8b1ff8 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit 46f6df10e59fa2af6cdb743010278c61d1f48441 +Subproject commit 1befeb8b1ff8b16b0c24715a4d8aac372ec04d6f diff --git a/build/terraform-mapper b/build/terraform-mapper index 1409249c1f3b..5f4baa9e1222 160000 --- a/build/terraform-mapper +++ b/build/terraform-mapper @@ -1 +1 @@ -Subproject commit 1409249c1f3b31457812671b2c73fd25874381fd +Subproject commit 5f4baa9e1222851fa7c70deb4746df9ea4b07f6d diff --git a/third_party/terraform/utils/common_operation.go b/third_party/terraform/utils/common_operation.go index 1c2a7577dfa9..c751ece87384 100644 --- a/third_party/terraform/utils/common_operation.go +++ b/third_party/terraform/utils/common_operation.go @@ -18,6 +18,9 @@ type Waiter interface { // if the operation has no current error. Error() error + // IsRetryable returns whether a given error should be retried. + IsRetryable(error) bool + // SetOp sets the operation we're waiting on in a Waiter struct so that it // can be used in other methods. SetOp(interface{}) error @@ -59,6 +62,10 @@ func (w *CommonOperationWaiter) Error() error { return nil } +func (w *CommonOperationWaiter) IsRetryable(error) bool { + return false +} + func (w *CommonOperationWaiter) SetOp(op interface{}) error { if err := Convert(op, &w.Op); err != nil { return err @@ -110,6 +117,10 @@ func CommonRefreshFunc(w Waiter) resource.StateRefreshFunc { } if err = w.Error(); err != nil { + if w.IsRetryable(err) { + log.Printf("[DEBUG] Retrying operation GET based on retryable err: %s", err) + return op, w.State(), nil + } return nil, "", err } diff --git a/third_party/terraform/utils/compute_operation.go b/third_party/terraform/utils/compute_operation.go index 992d59615436..25e266416487 100644 --- a/third_party/terraform/utils/compute_operation.go +++ b/third_party/terraform/utils/compute_operation.go @@ -29,6 +29,17 @@ func (w *ComputeOperationWaiter) Error() error { return nil } +func (w *ComputeOperationWaiter) IsRetryable(err error) bool { + if oe, ok := err.(ComputeOperationError); ok { + for _, e := range oe.Errors { + if e.Code == "RESOURCE_NOT_READY" { + return true + } + } + } + return false +} + func (w *ComputeOperationWaiter) SetOp(op interface{}) error { var ok bool w.Op, ok = op.(*compute.Operation) diff --git a/third_party/terraform/utils/container_operation.go b/third_party/terraform/utils/container_operation.go index 9c376ea15f88..99984f0f5360 100644 --- a/third_party/terraform/utils/container_operation.go +++ b/third_party/terraform/utils/container_operation.go @@ -41,6 +41,10 @@ func (w *ContainerOperationWaiter) Error() error { return nil } +func (w *ContainerOperationWaiter) IsRetryable(error) bool { + return false +} + func (w *ContainerOperationWaiter) SetOp(op interface{}) error { var ok bool w.Op, ok = op.(*container.Operation) diff --git a/third_party/terraform/utils/dataproc_job_operation.go b/third_party/terraform/utils/dataproc_job_operation.go index ce3cab01ee71..1efccf60eda7 100644 --- a/third_party/terraform/utils/dataproc_job_operation.go +++ b/third_party/terraform/utils/dataproc_job_operation.go @@ -28,6 +28,10 @@ func (w *DataprocJobOperationWaiter) Error() error { return nil } +func (w *DataprocJobOperationWaiter) IsRetryable(error) bool { + return false +} + func (w *DataprocJobOperationWaiter) SetOp(job interface{}) error { // The "operation" is just the job. Instead of holding onto the whole job // object, we only care about the state, which gets set in QueryOp, so this diff --git a/third_party/terraform/utils/sqladmin_operation.go b/third_party/terraform/utils/sqladmin_operation.go index 5f4094c699da..8ca847eeb8f4 100644 --- a/third_party/terraform/utils/sqladmin_operation.go +++ b/third_party/terraform/utils/sqladmin_operation.go @@ -33,6 +33,10 @@ func (w *SqlAdminOperationWaiter) Error() error { return nil } +func (w *SqlAdminOperationWaiter) IsRetryable(error) bool { + return false +} + func (w *SqlAdminOperationWaiter) SetOp(op interface{}) error { if op == nil { // Starting as a log statement, this may be a useful error in the future