Skip to content

Commit a2ae208

Browse files
authored
r/sagemaker_app - new resource (#17251)
1 parent 9018311 commit a2ae208

14 files changed

Lines changed: 1066 additions & 80 deletions

.changelog/17251.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```release-note:new-resource
2+
aws_sagemaker_app
3+
```
4+
5+
```release-note:enhancement
6+
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.
7+
```
8+
9+
```release-note:bug
10+
resource/aws_sagemaker_domain: Wait for update to finish.
11+
```
12+
13+
```release-note:bug
14+
resource/aws_sagemaker_user_profile: Wait for update to finish.
15+
```

aws/internal/service/sagemaker/finder/finder.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,25 @@ func AppImageConfigByName(conn *sagemaker.SageMaker, appImageConfigID string) (*
157157

158158
return output, nil
159159
}
160+
161+
// AppByName returns the domain corresponding to the specified domain id.
162+
// Returns nil if no domain is found.
163+
func AppByName(conn *sagemaker.SageMaker, domainID, userProfileName, appType, appName string) (*sagemaker.DescribeAppOutput, error) {
164+
input := &sagemaker.DescribeAppInput{
165+
DomainId: aws.String(domainID),
166+
UserProfileName: aws.String(userProfileName),
167+
AppType: aws.String(appType),
168+
AppName: aws.String(appName),
169+
}
170+
171+
output, err := conn.DescribeApp(input)
172+
if err != nil {
173+
return nil, err
174+
}
175+
176+
if output == nil {
177+
return nil, nil
178+
}
179+
180+
return output, nil
181+
}

aws/internal/service/sagemaker/waiter/status.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
SagemakerFeatureGroupStatusUnknown = "Unknown"
2222
SagemakerUserProfileStatusNotFound = "NotFound"
2323
SagemakerModelPackageGroupStatusNotFound = "NotFound"
24+
SagemakerAppStatusNotFound = "NotFound"
2425
)
2526

2627
// NotebookInstanceStatus fetches the NotebookInstance and its Status
@@ -201,3 +202,31 @@ func UserProfileStatus(conn *sagemaker.SageMaker, domainID, userProfileName stri
201202
return output, aws.StringValue(output.Status), nil
202203
}
203204
}
205+
206+
// AppStatus fetches the App and its Status
207+
func AppStatus(conn *sagemaker.SageMaker, domainID, userProfileName, appType, appName string) resource.StateRefreshFunc {
208+
return func() (interface{}, string, error) {
209+
input := &sagemaker.DescribeAppInput{
210+
DomainId: aws.String(domainID),
211+
UserProfileName: aws.String(userProfileName),
212+
AppType: aws.String(appType),
213+
AppName: aws.String(appName),
214+
}
215+
216+
output, err := conn.DescribeApp(input)
217+
218+
if tfawserr.ErrMessageContains(err, "ValidationException", "RecordNotFound") {
219+
return nil, SagemakerAppStatusNotFound, nil
220+
}
221+
222+
if err != nil {
223+
return nil, sagemaker.AppStatusFailed, err
224+
}
225+
226+
if output == nil {
227+
return nil, SagemakerAppStatusNotFound, nil
228+
}
229+
230+
return output, aws.StringValue(output.Status), nil
231+
}
232+
}

aws/internal/service/sagemaker/waiter/waiter.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const (
2323
FeatureGroupDeletedTimeout = 10 * time.Minute
2424
UserProfileInServiceTimeout = 10 * time.Minute
2525
UserProfileDeletedTimeout = 10 * time.Minute
26+
AppInServiceTimeout = 10 * time.Minute
27+
AppDeletedTimeout = 10 * time.Minute
2628
)
2729

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

326329
return nil, err
327330
}
331+
332+
// AppInService waits for a App to return InService
333+
func AppInService(conn *sagemaker.SageMaker, domainID, userProfileName, appType, appName string) (*sagemaker.DescribeAppOutput, error) {
334+
stateConf := &resource.StateChangeConf{
335+
Pending: []string{
336+
SagemakerAppStatusNotFound,
337+
sagemaker.AppStatusPending,
338+
},
339+
Target: []string{sagemaker.AppStatusInService},
340+
Refresh: AppStatus(conn, domainID, userProfileName, appType, appName),
341+
Timeout: AppInServiceTimeout,
342+
}
343+
344+
outputRaw, err := stateConf.WaitForState()
345+
346+
if output, ok := outputRaw.(*sagemaker.DescribeAppOutput); ok {
347+
return output, err
348+
}
349+
350+
return nil, err
351+
}
352+
353+
// AppDeleted waits for a App to return Deleted
354+
func AppDeleted(conn *sagemaker.SageMaker, domainID, userProfileName, appType, appName string) (*sagemaker.DescribeAppOutput, error) {
355+
stateConf := &resource.StateChangeConf{
356+
Pending: []string{
357+
sagemaker.AppStatusDeleting,
358+
},
359+
Target: []string{
360+
sagemaker.AppStatusDeleted,
361+
},
362+
Refresh: AppStatus(conn, domainID, userProfileName, appType, appName),
363+
Timeout: AppDeletedTimeout,
364+
}
365+
366+
outputRaw, err := stateConf.WaitForState()
367+
368+
if output, ok := outputRaw.(*sagemaker.DescribeAppOutput); ok {
369+
return output, err
370+
}
371+
372+
return nil, err
373+
}

aws/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,7 @@ func Provider() *schema.Provider {
895895
"aws_route_table": resourceAwsRouteTable(),
896896
"aws_default_route_table": resourceAwsDefaultRouteTable(),
897897
"aws_route_table_association": resourceAwsRouteTableAssociation(),
898+
"aws_sagemaker_app": resourceAwsSagemakerApp(),
898899
"aws_sagemaker_app_image_config": resourceAwsSagemakerAppImageConfig(),
899900
"aws_sagemaker_code_repository": resourceAwsSagemakerCodeRepository(),
900901
"aws_sagemaker_domain": resourceAwsSagemakerDomain(),

0 commit comments

Comments
 (0)