diff --git a/aws/resource_aws_sagemaker_model.go b/aws/resource_aws_sagemaker_model.go index 8da56ad3f04..c6c1e0036b0 100644 --- a/aws/resource_aws_sagemaker_model.go +++ b/aws/resource_aws_sagemaker_model.go @@ -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 { diff --git a/aws/resource_aws_sagemaker_notebook_instance.go b/aws/resource_aws_sagemaker_notebook_instance.go index 07533b02507..4b7b3bc65fa 100644 --- a/aws/resource_aws_sagemaker_notebook_instance.go +++ b/aws/resource_aws_sagemaker_notebook_instance.go @@ -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,