Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retry on resourceNotReady #2307

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is a display glitch or not, but spacing looks weird here.

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" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

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