Skip to content

Commit

Permalink
retry on resourceNotReady (#2307)
Browse files Browse the repository at this point in the history
Merged PR #2307.
  • Loading branch information
danawillow authored and modular-magician committed Sep 12, 2019
1 parent 37b9255 commit 263f4ad
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
2 changes: 1 addition & 1 deletion build/terraform-mapper
11 changes: 11 additions & 0 deletions third_party/terraform/utils/common_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
11 changes: 11 additions & 0 deletions third_party/terraform/utils/compute_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions third_party/terraform/utils/container_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions third_party/terraform/utils/dataproc_job_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions third_party/terraform/utils/sqladmin_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 263f4ad

Please sign in to comment.