-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15385 from DrFaust92/r/sagemaker_instance_refactor
r/sagemaker_notebook_instance - `lifecycle_config_name`, `root_access`, and `default_code_repository` allow updating + refactor tests
- Loading branch information
Showing
4 changed files
with
444 additions
and
483 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package waiter | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/sagemaker" | ||
"github.com/hashicorp/aws-sdk-go-base/tfawserr" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
const ( | ||
SagemakerNotebookInstanceStatusNotFound = "NotFound" | ||
) | ||
|
||
// NotebookInstanceStatus fetches the NotebookInstance and its Status | ||
func NotebookInstanceStatus(conn *sagemaker.SageMaker, notebookName string) resource.StateRefreshFunc { | ||
return func() (interface{}, string, error) { | ||
input := &sagemaker.DescribeNotebookInstanceInput{ | ||
NotebookInstanceName: aws.String(notebookName), | ||
} | ||
|
||
output, err := conn.DescribeNotebookInstance(input) | ||
|
||
if tfawserr.ErrMessageContains(err, "ValidationException", "RecordNotFound") { | ||
return nil, SagemakerNotebookInstanceStatusNotFound, nil | ||
} | ||
|
||
if err != nil { | ||
return nil, sagemaker.NotebookInstanceStatusFailed, err | ||
} | ||
|
||
if output == nil { | ||
return nil, SagemakerNotebookInstanceStatusNotFound, nil | ||
} | ||
|
||
return output, aws.StringValue(output.NotebookInstanceStatus), nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package waiter | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/service/sagemaker" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
const ( | ||
NotebookInstanceInServiceTimeout = 10 * time.Minute | ||
NotebookInstanceStoppedTimeout = 10 * time.Minute | ||
NotebookInstanceDeletedTimeout = 10 * time.Minute | ||
) | ||
|
||
// NotebookInstanceInService waits for a NotebookInstance to return InService | ||
func NotebookInstanceInService(conn *sagemaker.SageMaker, notebookName string) (*sagemaker.DescribeNotebookInstanceOutput, error) { | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{ | ||
SagemakerNotebookInstanceStatusNotFound, | ||
sagemaker.NotebookInstanceStatusUpdating, | ||
sagemaker.NotebookInstanceStatusPending, | ||
sagemaker.NotebookInstanceStatusStopped, | ||
}, | ||
Target: []string{sagemaker.NotebookInstanceStatusInService}, | ||
Refresh: NotebookInstanceStatus(conn, notebookName), | ||
Timeout: NotebookInstanceInServiceTimeout, | ||
} | ||
|
||
outputRaw, err := stateConf.WaitForState() | ||
|
||
if output, ok := outputRaw.(*sagemaker.DescribeNotebookInstanceOutput); ok { | ||
return output, err | ||
} | ||
|
||
return nil, err | ||
} | ||
|
||
// NotebookInstanceStopped waits for a NotebookInstance to return Stopped | ||
func NotebookInstanceStopped(conn *sagemaker.SageMaker, notebookName string) (*sagemaker.DescribeNotebookInstanceOutput, error) { | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{ | ||
sagemaker.NotebookInstanceStatusUpdating, | ||
sagemaker.NotebookInstanceStatusStopping, | ||
}, | ||
Target: []string{sagemaker.NotebookInstanceStatusStopped}, | ||
Refresh: NotebookInstanceStatus(conn, notebookName), | ||
Timeout: NotebookInstanceStoppedTimeout, | ||
} | ||
|
||
outputRaw, err := stateConf.WaitForState() | ||
|
||
if output, ok := outputRaw.(*sagemaker.DescribeNotebookInstanceOutput); ok { | ||
return output, err | ||
} | ||
|
||
return nil, err | ||
} | ||
|
||
// NotebookInstanceDeleted waits for a NotebookInstance to return Deleted | ||
func NotebookInstanceDeleted(conn *sagemaker.SageMaker, notebookName string) (*sagemaker.DescribeNotebookInstanceOutput, error) { | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{ | ||
sagemaker.NotebookInstanceStatusDeleting, | ||
}, | ||
Target: []string{}, | ||
Refresh: NotebookInstanceStatus(conn, notebookName), | ||
Timeout: NotebookInstanceDeletedTimeout, | ||
} | ||
|
||
outputRaw, err := stateConf.WaitForState() | ||
|
||
if output, ok := outputRaw.(*sagemaker.DescribeNotebookInstanceOutput); ok { | ||
return output, err | ||
} | ||
|
||
return nil, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.