Skip to content

Commit

Permalink
Merge pull request #39808 from DrFaust92/sagemaker-app-error
Browse files Browse the repository at this point in the history
r/sagemaker_app_image and image_version - log errors better
  • Loading branch information
ewbankkit authored Oct 21, 2024
2 parents c61a381 + 8e62a90 commit 5ac4b2b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/service/sagemaker/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func resourceImageDelete(ctx context.Context, d *schema.ResourceData, meta inter
return sdkdiag.AppendErrorf(diags, "deleting SageMaker Image (%s): %s", d.Id(), err)
}

if _, err := waitImageDeleted(ctx, conn, d.Id()); err != nil {
if err := waitImageDeleted(ctx, conn, d.Id()); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for SageMaker Image (%s) to delete: %s", d.Id(), err)
}

Expand Down
28 changes: 24 additions & 4 deletions internal/service/sagemaker/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,20 @@ func waitImageCreated(ctx context.Context, conn *sagemaker.Client, name string)
Timeout: imageCreatedTimeout,
}

_, err := stateConf.WaitForStateContext(ctx)
outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*sagemaker.DescribeImageOutput); ok {
if status, reason := output.ImageStatus, aws.ToString(output.FailureReason); (status == awstypes.ImageStatusCreateFailed || status == awstypes.ImageStatusUpdateFailed) && reason != "" {
tfresource.SetLastError(err, errors.New(reason))
}

return err
}

return err
}

func waitImageDeleted(ctx context.Context, conn *sagemaker.Client, name string) (*sagemaker.DescribeImageOutput, error) {
func waitImageDeleted(ctx context.Context, conn *sagemaker.Client, name string) error {
stateConf := &retry.StateChangeConf{
Pending: enum.Slice(awstypes.ImageStatusDeleting),
Target: []string{},
Expand All @@ -194,10 +202,14 @@ func waitImageDeleted(ctx context.Context, conn *sagemaker.Client, name string)
outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*sagemaker.DescribeImageOutput); ok {
return output, err
if status, reason := output.ImageStatus, aws.ToString(output.FailureReason); status == awstypes.ImageStatusDeleteFailed && reason != "" {
tfresource.SetLastError(err, errors.New(reason))
}

return err
}

return nil, err
return err
}

func waitImageVersionCreated(ctx context.Context, conn *sagemaker.Client, name string) (*sagemaker.DescribeImageVersionOutput, error) {
Expand All @@ -211,6 +223,10 @@ func waitImageVersionCreated(ctx context.Context, conn *sagemaker.Client, name s
outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*sagemaker.DescribeImageVersionOutput); ok {
if status, reason := output.ImageVersionStatus, aws.ToString(output.FailureReason); status == awstypes.ImageVersionStatusCreateFailed && reason != "" {
tfresource.SetLastError(err, errors.New(reason))
}

return output, err
}

Expand All @@ -228,6 +244,10 @@ func waitImageVersionDeleted(ctx context.Context, conn *sagemaker.Client, name s
outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*sagemaker.DescribeImageVersionOutput); ok {
if status, reason := output.ImageVersionStatus, aws.ToString(output.FailureReason); status == awstypes.ImageVersionStatusDeleteFailed && reason != "" {
tfresource.SetLastError(err, errors.New(reason))
}

return output, err
}

Expand Down

0 comments on commit 5ac4b2b

Please sign in to comment.