Skip to content

Commit

Permalink
r/sagemaker_app - new resource (#17251)
Browse files Browse the repository at this point in the history
  • Loading branch information
DrFaust92 committed Feb 25, 2021
1 parent 9018311 commit a2ae208
Show file tree
Hide file tree
Showing 14 changed files with 1,066 additions and 80 deletions.
15 changes: 15 additions & 0 deletions .changelog/17251.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```release-note:new-resource
aws_sagemaker_app
```

```release-note:enhancement
resource/aws_sagemaker_domain: Make `default_resource_spec` optional for the `tensor_board_app_settings`, `jupyter_server_app_settings` and `kernel_gateway_app_settings` config blocks.
```

```release-note:bug
resource/aws_sagemaker_domain: Wait for update to finish.
```

```release-note:bug
resource/aws_sagemaker_user_profile: Wait for update to finish.
```
22 changes: 22 additions & 0 deletions aws/internal/service/sagemaker/finder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,25 @@ func AppImageConfigByName(conn *sagemaker.SageMaker, appImageConfigID string) (*

return output, nil
}

// AppByName returns the domain corresponding to the specified domain id.
// Returns nil if no domain is found.
func AppByName(conn *sagemaker.SageMaker, domainID, userProfileName, appType, appName string) (*sagemaker.DescribeAppOutput, error) {
input := &sagemaker.DescribeAppInput{
DomainId: aws.String(domainID),
UserProfileName: aws.String(userProfileName),
AppType: aws.String(appType),
AppName: aws.String(appName),
}

output, err := conn.DescribeApp(input)
if err != nil {
return nil, err
}

if output == nil {
return nil, nil
}

return output, nil
}
29 changes: 29 additions & 0 deletions aws/internal/service/sagemaker/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
SagemakerFeatureGroupStatusUnknown = "Unknown"
SagemakerUserProfileStatusNotFound = "NotFound"
SagemakerModelPackageGroupStatusNotFound = "NotFound"
SagemakerAppStatusNotFound = "NotFound"
)

// NotebookInstanceStatus fetches the NotebookInstance and its Status
Expand Down Expand Up @@ -201,3 +202,31 @@ func UserProfileStatus(conn *sagemaker.SageMaker, domainID, userProfileName stri
return output, aws.StringValue(output.Status), nil
}
}

// AppStatus fetches the App and its Status
func AppStatus(conn *sagemaker.SageMaker, domainID, userProfileName, appType, appName string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
input := &sagemaker.DescribeAppInput{
DomainId: aws.String(domainID),
UserProfileName: aws.String(userProfileName),
AppType: aws.String(appType),
AppName: aws.String(appName),
}

output, err := conn.DescribeApp(input)

if tfawserr.ErrMessageContains(err, "ValidationException", "RecordNotFound") {
return nil, SagemakerAppStatusNotFound, nil
}

if err != nil {
return nil, sagemaker.AppStatusFailed, err
}

if output == nil {
return nil, SagemakerAppStatusNotFound, nil
}

return output, aws.StringValue(output.Status), nil
}
}
46 changes: 46 additions & 0 deletions aws/internal/service/sagemaker/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
FeatureGroupDeletedTimeout = 10 * time.Minute
UserProfileInServiceTimeout = 10 * time.Minute
UserProfileDeletedTimeout = 10 * time.Minute
AppInServiceTimeout = 10 * time.Minute
AppDeletedTimeout = 10 * time.Minute
)

// NotebookInstanceInService waits for a NotebookInstance to return InService
Expand Down Expand Up @@ -213,6 +215,7 @@ func DomainInService(conn *sagemaker.SageMaker, domainID string) (*sagemaker.Des
Pending: []string{
SagemakerDomainStatusNotFound,
sagemaker.DomainStatusPending,
sagemaker.DomainStatusUpdating,
},
Target: []string{sagemaker.DomainStatusInService},
Refresh: DomainStatus(conn, domainID),
Expand Down Expand Up @@ -325,3 +328,46 @@ func UserProfileDeleted(conn *sagemaker.SageMaker, domainID, userProfileName str

return nil, err
}

// AppInService waits for a App to return InService
func AppInService(conn *sagemaker.SageMaker, domainID, userProfileName, appType, appName string) (*sagemaker.DescribeAppOutput, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{
SagemakerAppStatusNotFound,
sagemaker.AppStatusPending,
},
Target: []string{sagemaker.AppStatusInService},
Refresh: AppStatus(conn, domainID, userProfileName, appType, appName),
Timeout: AppInServiceTimeout,
}

outputRaw, err := stateConf.WaitForState()

if output, ok := outputRaw.(*sagemaker.DescribeAppOutput); ok {
return output, err
}

return nil, err
}

// AppDeleted waits for a App to return Deleted
func AppDeleted(conn *sagemaker.SageMaker, domainID, userProfileName, appType, appName string) (*sagemaker.DescribeAppOutput, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{
sagemaker.AppStatusDeleting,
},
Target: []string{
sagemaker.AppStatusDeleted,
},
Refresh: AppStatus(conn, domainID, userProfileName, appType, appName),
Timeout: AppDeletedTimeout,
}

outputRaw, err := stateConf.WaitForState()

if output, ok := outputRaw.(*sagemaker.DescribeAppOutput); ok {
return output, err
}

return nil, err
}
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ func Provider() *schema.Provider {
"aws_route_table": resourceAwsRouteTable(),
"aws_default_route_table": resourceAwsDefaultRouteTable(),
"aws_route_table_association": resourceAwsRouteTableAssociation(),
"aws_sagemaker_app": resourceAwsSagemakerApp(),
"aws_sagemaker_app_image_config": resourceAwsSagemakerAppImageConfig(),
"aws_sagemaker_code_repository": resourceAwsSagemakerCodeRepository(),
"aws_sagemaker_domain": resourceAwsSagemakerDomain(),
Expand Down
Loading

0 comments on commit a2ae208

Please sign in to comment.