Skip to content

Commit

Permalink
Merge pull request #9799 from terraform-providers/rfd-retry-sagemaker
Browse files Browse the repository at this point in the history
Final sagemaker retries
  • Loading branch information
ryndaniels authored Aug 20, 2019
2 parents c7ab4e3 + 10dcd9e commit d50ae33
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
19 changes: 10 additions & 9 deletions aws/resource_aws_sagemaker_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,23 +305,24 @@ func resourceAwsSagemakerModelDelete(d *schema.ResourceData, meta interface{}) e
}
log.Printf("[INFO] Deleting Sagemaker model: %s", d.Id())

return resource.Retry(5*time.Minute, func() *resource.RetryError {
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteModel(deleteOpts)
if err == nil {
return nil
}

sagemakerErr, ok := err.(awserr.Error)
if !ok {
return resource.NonRetryableError(err)
}

if sagemakerErr.Code() == "ResourceNotFound" {
if isAWSErr(err, "ResourceNotFound", "") {
return resource.RetryableError(err)
}

return resource.NonRetryableError(fmt.Errorf("error deleting Sagemaker model: %s", err))
return resource.NonRetryableError(err)
})
if isResourceTimeoutError(err) {
_, err = conn.DeleteModel(deleteOpts)
}
if err != nil {
return fmt.Errorf("Error deleting sagemaker model: %s", err)
}
return nil
}

func expandContainer(m map[string]interface{}) *sagemaker.ContainerDefinition {
Expand Down
35 changes: 22 additions & 13 deletions aws/resource_aws_sagemaker_notebook_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,33 +248,42 @@ func resourceAwsSagemakerNotebookInstanceUpdate(d *schema.ResourceData, meta int
startOpts := &sagemaker.StartNotebookInstanceInput{
NotebookInstanceName: aws.String(d.Id()),
}

stateConf := &resource.StateChangeConf{
Pending: []string{
sagemaker.NotebookInstanceStatusStopped,
},
Target: []string{sagemaker.NotebookInstanceStatusInService, sagemaker.NotebookInstanceStatusPending},
Refresh: sagemakerNotebookInstanceStateRefreshFunc(conn, d.Id()),
Timeout: 30 * time.Second,
}
// StartNotebookInstance sometimes doesn't take so we'll check for a state change and if
// it doesn't change we'll send another request
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
if _, err := conn.StartNotebookInstance(startOpts); err != nil {
_, err := conn.StartNotebookInstance(startOpts)
if err != nil {
return resource.NonRetryableError(fmt.Errorf("error starting sagemaker notebook instance (%s): %s", d.Id(), err))
}
stateConf := &resource.StateChangeConf{
Pending: []string{
sagemaker.NotebookInstanceStatusStopped,
},
Target: []string{sagemaker.NotebookInstanceStatusInService, sagemaker.NotebookInstanceStatusPending},
Refresh: sagemakerNotebookInstanceStateRefreshFunc(conn, d.Id()),
Timeout: 30 * time.Second,
}
_, err := stateConf.WaitForState()

_, err = stateConf.WaitForState()
if err != nil {
return resource.RetryableError(fmt.Errorf("error waiting for sagemaker notebook instance (%s) to start: %s", d.Id(), err))
}

return nil
})
if isResourceTimeoutError(err) {
_, err = conn.StartNotebookInstance(startOpts)
if err != nil {
return fmt.Errorf("error starting sagemaker notebook instance (%s): %s", d.Id(), err)
}

_, err = stateConf.WaitForState()
}
if err != nil {
return err
return fmt.Errorf("Error waiting for sagemaker notebook instance to start: %s", err)
}

stateConf := &resource.StateChangeConf{
stateConf = &resource.StateChangeConf{
Pending: []string{
sagemaker.NotebookInstanceStatusUpdating,
sagemaker.NotebookInstanceStatusPending,
Expand Down

0 comments on commit d50ae33

Please sign in to comment.