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 - add args #34283

Merged
merged 10 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/34283.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_sagemaker_feature_group: Add `offline_store_config.s3_storage_config.resolved_output_s3_uri`, `online_store_config.storage_type` and `online_store_config.ttl_duration` arguments
```

```release-note:enhancement
resource/aws_sagemaker_feature_group: Allow `online_store_config.ttl_duration` to be updated in-place
```
129 changes: 128 additions & 1 deletion internal/service/sagemaker/feature_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func ResourceFeatureGroup() *schema.Resource {
"feature_name": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 64),
validation.StringNotInSlice([]string{"is_deleted", "write_time", "api_invocation_time"}, false),
Expand All @@ -77,6 +78,7 @@ func ResourceFeatureGroup() *schema.Resource {
"feature_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(sagemaker.FeatureType_Values(), false),
},
},
Expand Down Expand Up @@ -104,52 +106,67 @@ func ResourceFeatureGroup() *schema.Resource {
Type: schema.TypeList,
Optional: true,
Computed: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"catalog": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"database": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"table_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
},
},
},
"disable_glue_table_creation": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"s3_storage_config": {
Type: schema.TypeList,
Required: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"kms_key_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidARN,
},
"resolved_output_s3_uri": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"s3_uri": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
},
},
},
"table_format": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: sagemaker.TableFormatGlue,
ValidateFunc: validation.StringInSlice(sagemaker.TableFormat_Values(), false),
},
Expand All @@ -167,22 +184,49 @@ func ResourceFeatureGroup() *schema.Resource {
"enable_online_store": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Default: false,
},
"security_config": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"kms_key_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidARN,
},
},
},
},
"storage_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(sagemaker.StorageType_Values(), false),
},
"ttl_duration": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"unit": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(sagemaker.TtlDurationUnit_Values(), false),
},
"value": {
Type: schema.TypeInt,
Optional: true,
},
},
},
},
},
},
},
Expand Down Expand Up @@ -309,8 +353,23 @@ func resourceFeatureGroupRead(ctx context.Context, d *schema.ResourceData, meta

func resourceFeatureGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).SageMakerConn(ctx)

// Tags only.
if d.HasChangesExcept("tags", "tags_all") {
input := &sagemaker.UpdateFeatureGroupInput{
FeatureGroupName: aws.String(d.Id()),
}

if d.HasChange("online_store_config") {
input.OnlineStoreConfig = expandFeatureGroupOnlineStoreConfigUpdate(d.Get("online_store_config").([]interface{}))
}

_, err := conn.UpdateFeatureGroupWithContext(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "updating SageMaker Feature Group (%s): %s", d.Id(), err)
}
}

return append(diags, resourceFeatureGroupRead(ctx, d, meta)...)
}
Expand Down Expand Up @@ -386,6 +445,14 @@ func expandFeatureGroupOnlineStoreConfig(l []interface{}) *sagemaker.OnlineStore
config.SecurityConfig = expandFeatureGroupOnlineStoreConfigSecurityConfig(v)
}

if v, ok := m["storage_type"].(string); ok && v != "" {
config.StorageType = aws.String(v)
}

if v, ok := m["ttl_duration"].([]interface{}); ok && len(v) > 0 {
config.TtlDuration = expandFeatureGroupOnlineStoreConfigTTLDuration(v)
}

return config
}

Expand All @@ -402,6 +469,14 @@ func flattenFeatureGroupOnlineStoreConfig(config *sagemaker.OnlineStoreConfig) [
m["security_config"] = flattenFeatureGroupOnlineStoreConfigSecurityConfig(config.SecurityConfig)
}

if config.StorageType != nil {
m["storage_type"] = aws.StringValue(config.StorageType)
}

if config.TtlDuration != nil {
m["ttl_duration"] = flattenFeatureGroupOnlineStoreConfigTTLDuration(config.TtlDuration)
}

return []map[string]interface{}{m}
}

Expand Down Expand Up @@ -431,6 +506,34 @@ func flattenFeatureGroupOnlineStoreConfigSecurityConfig(config *sagemaker.Online
return []map[string]interface{}{m}
}

func expandFeatureGroupOnlineStoreConfigTTLDuration(l []interface{}) *sagemaker.TtlDuration {
if len(l) == 0 || l[0] == nil {
return nil
}

m := l[0].(map[string]interface{})

config := &sagemaker.TtlDuration{
Unit: aws.String(m["unit"].(string)),
Value: aws.Int64(int64(m["value"].(int))),
}

return config
}

func flattenFeatureGroupOnlineStoreConfigTTLDuration(config *sagemaker.TtlDuration) []map[string]interface{} {
if config == nil {
return []map[string]interface{}{}
}

m := map[string]interface{}{
"unit": aws.StringValue(config.Unit),
"value": aws.Int64Value(config.Value),
}

return []map[string]interface{}{m}
}

func expandFeatureGroupOfflineStoreConfig(l []interface{}) *sagemaker.OfflineStoreConfig {
if len(l) == 0 || l[0] == nil {
return nil
Expand Down Expand Up @@ -495,6 +598,10 @@ func expandFeatureGroupOfflineStoreConfigS3StorageConfig(l []interface{}) *sagem
config.KmsKeyId = aws.String(m["kms_key_id"].(string))
}

if v, ok := m["resolved_output_s3_uri"].(string); ok && v != "" {
config.ResolvedOutputS3Uri = aws.String(m["resolved_output_s3_uri"].(string))
}

return config
}

Expand All @@ -511,6 +618,10 @@ func flattenFeatureGroupOfflineStoreConfigS3StorageConfig(config *sagemaker.S3St
m["kms_key_id"] = aws.StringValue(config.KmsKeyId)
}

if config.ResolvedOutputS3Uri != nil {
m["resolved_output_s3_uri"] = aws.StringValue(config.ResolvedOutputS3Uri)
}

return []map[string]interface{}{m}
}

Expand Down Expand Up @@ -543,3 +654,19 @@ func flattenFeatureGroupOfflineStoreConfigDataCatalogConfig(config *sagemaker.Da

return []map[string]interface{}{m}
}

func expandFeatureGroupOnlineStoreConfigUpdate(l []interface{}) *sagemaker.OnlineStoreConfigUpdate {
if len(l) == 0 || l[0] == nil {
return nil
}

m := l[0].(map[string]interface{})

config := &sagemaker.OnlineStoreConfigUpdate{}

if v, ok := m["ttl_duration"].([]interface{}); ok && len(v) > 0 {
config.TtlDuration = expandFeatureGroupOnlineStoreConfigTTLDuration(v)
}

return config
}
Loading
Loading