Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/sagemaker_feature_group - new resource #16728

Merged
merged 20 commits into from
Jan 18, 2021
Merged
19 changes: 19 additions & 0 deletions aws/internal/service/sagemaker/finder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,22 @@ func DomainByName(conn *sagemaker.SageMaker, domainID string) (*sagemaker.Descri

return output, nil
}

// FeatureGroupByName returns the feature group corresponding to the specified name.
// Returns nil if no feature group is found.
func FeatureGroupByName(conn *sagemaker.SageMaker, name string) (*sagemaker.DescribeFeatureGroupOutput, error) {
input := &sagemaker.DescribeFeatureGroupInput{
FeatureGroupName: aws.String(name),
}

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

if output == nil {
return nil, nil
}

return output, nil
}
23 changes: 23 additions & 0 deletions aws/internal/service/sagemaker/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import (
"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"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/sagemaker/finder"
)

const (
SagemakerNotebookInstanceStatusNotFound = "NotFound"
SagemakerImageStatusNotFound = "NotFound"
SagemakerImageStatusFailed = "Failed"
SagemakerDomainStatusNotFound = "NotFound"
SagemakerFeatureGroupStatusNotFound = "NotFound"
SagemakerFeatureGroupStatusUnknown = "Unknown"
)

// NotebookInstanceStatus fetches the NotebookInstance and its Status
Expand Down Expand Up @@ -94,3 +97,23 @@ func DomainStatus(conn *sagemaker.SageMaker, domainID string) resource.StateRefr
return output, aws.StringValue(output.Status), nil
}
}

// FeatureGroupStatus fetches the Feature Group and its Status
func FeatureGroupStatus(conn *sagemaker.SageMaker, name string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := finder.FeatureGroupByName(conn, name)
if tfawserr.ErrCodeEquals(err, sagemaker.ErrCodeResourceNotFound) {
return nil, SagemakerFeatureGroupStatusNotFound, nil
}

if err != nil {
return nil, SagemakerFeatureGroupStatusUnknown, err
}

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

return output, aws.StringValue(output.FeatureGroupStatus), nil
}
}
38 changes: 38 additions & 0 deletions aws/internal/service/sagemaker/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const (
ImageDeletedTimeout = 10 * time.Minute
DomainInServiceTimeout = 10 * time.Minute
DomainDeletedTimeout = 10 * time.Minute
FeatureGroupCreatedTimeout = 10 * time.Minute
FeatureGroupDeletedTimeout = 10 * time.Minute
)

// NotebookInstanceInService waits for a NotebookInstance to return InService
Expand Down Expand Up @@ -160,3 +162,39 @@ func DomainDeleted(conn *sagemaker.SageMaker, domainID string) (*sagemaker.Descr

return nil, err
}

// FeatureGroupCreated waits for a Feature Group to return Created
func FeatureGroupCreated(conn *sagemaker.SageMaker, name string) (*sagemaker.DescribeFeatureGroupOutput, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{sagemaker.FeatureGroupStatusCreating},
Target: []string{sagemaker.FeatureGroupStatusCreated},
Refresh: FeatureGroupStatus(conn, name),
Timeout: FeatureGroupCreatedTimeout,
}

outputRaw, err := stateConf.WaitForState()

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

return nil, err
}

// FeatureGroupDeleted waits for a Feature Group to return Deleted
func FeatureGroupDeleted(conn *sagemaker.SageMaker, name string) (*sagemaker.DescribeFeatureGroupOutput, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{sagemaker.FeatureGroupStatusDeleting},
Target: []string{},
Refresh: FeatureGroupStatus(conn, name),
Timeout: FeatureGroupDeletedTimeout,
}

outputRaw, err := stateConf.WaitForState()

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

return nil, err
}
3 changes: 2 additions & 1 deletion aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,9 +874,10 @@ func Provider() *schema.Provider {
"aws_route_table_association": resourceAwsRouteTableAssociation(),
"aws_sagemaker_code_repository": resourceAwsSagemakerCodeRepository(),
"aws_sagemaker_domain": resourceAwsSagemakerDomain(),
"aws_sagemaker_endpoint": resourceAwsSagemakerEndpoint(),
"aws_sagemaker_endpoint_configuration": resourceAwsSagemakerEndpointConfiguration(),
"aws_sagemaker_feature_group": resourceAwsSagemakerFeatureGroup(),
"aws_sagemaker_image": resourceAwsSagemakerImage(),
"aws_sagemaker_endpoint": resourceAwsSagemakerEndpoint(),
"aws_sagemaker_model": resourceAwsSagemakerModel(),
"aws_sagemaker_notebook_instance_lifecycle_configuration": resourceAwsSagemakerNotebookInstanceLifeCycleConfiguration(),
"aws_sagemaker_notebook_instance": resourceAwsSagemakerNotebookInstance(),
Expand Down
Loading