Skip to content

F aws sagemaker endpoint configuration inference component support #40654

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
40 changes: 29 additions & 11 deletions internal/service/sagemaker/endpoint_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func resourceEndpointConfiguration() *schema.Resource {
},
"model_name": {
Type: schema.TypeString,
Required: true,
Optional: true,
ForceNew: true,
},
"routing_config": {
Expand Down Expand Up @@ -592,6 +592,12 @@ func resourceEndpointConfiguration() *schema.Resource {
},
},
},
"execution_role_arn": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidARN,
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
},
Expand All @@ -616,6 +622,10 @@ func resourceEndpointConfigurationCreate(ctx context.Context, d *schema.Resource
createOpts.KmsKeyId = aws.String(v.(string))
}

if v, ok := d.GetOk("execution_role_arn"); ok {
createOpts.ExecutionRoleArn = aws.String(v.(string))
}

if v, ok := d.GetOk("shadow_production_variants"); ok && len(v.([]interface{})) > 0 {
createOpts.ShadowProductionVariants = expandProductionVariants(v.([]interface{}))
}
Expand Down Expand Up @@ -739,8 +749,10 @@ func expandProductionVariants(configured []interface{}) []awstypes.ProductionVar
for _, lRaw := range configured {
data := lRaw.(map[string]interface{})

l := awstypes.ProductionVariant{
ModelName: aws.String(data["model_name"].(string)),
l := awstypes.ProductionVariant{}

if v, ok := data["model_name"].(string); ok && v != "" {
l.ModelName = aws.String(v)
}

if v, ok := data["initial_instance_count"].(int); ok && v > 0 {
Expand Down Expand Up @@ -769,10 +781,17 @@ func expandProductionVariants(configured []interface{}) []awstypes.ProductionVar
l.VariantName = aws.String(id.UniqueId())
}

if v, ok := data["initial_variant_weight"].(float64); ok {
l.InitialVariantWeight = aws.Float32(float32(v))
}
// Do not set initial variant weight or SSM access if we're using inference components
// Inference component usage is determined by a nonexistent model_name
if modelName, ok := data["model_name"].(string); ok && modelName != "" {
if v, ok := data["initial_variant_weight"].(float64); ok {
l.InitialVariantWeight = aws.Float32(float32(v))
}

if v, ok := data["enable_ssm_access"].(bool); ok {
l.EnableSSMAccess = aws.Bool(v)
}
}
if v, ok := data["accelerator_type"].(string); ok && v != "" {
l.AcceleratorType = awstypes.ProductionVariantAcceleratorType(v)
}
Expand All @@ -789,10 +808,6 @@ func expandProductionVariants(configured []interface{}) []awstypes.ProductionVar
l.CoreDumpConfig = expandCoreDumpConfig(v)
}

if v, ok := data["enable_ssm_access"].(bool); ok {
l.EnableSSMAccess = aws.Bool(v)
}

if v, ok := data["managed_instance_scaling"].([]interface{}); ok && len(v) > 0 {
l.ManagedInstanceScaling = expandManagedInstanceScaling(v)
}
Expand All @@ -816,10 +831,13 @@ func flattenProductionVariants(list []awstypes.ProductionVariant) []map[string]i
names.AttrInstanceType: i.InstanceType,
"inference_ami_version": i.InferenceAmiVersion,
"initial_variant_weight": aws.ToFloat32(i.InitialVariantWeight),
"model_name": aws.ToString(i.ModelName),
"variant_name": aws.ToString(i.VariantName),
}

if i.ModelName != nil {
l["model_name"] = aws.ToString(i.ModelName)
}

if i.InitialInstanceCount != nil {
l["initial_instance_count"] = aws.ToInt32(i.InitialInstanceCount)
}
Expand Down
51 changes: 51 additions & 0 deletions internal/service/sagemaker/endpoint_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,37 @@ func TestAccSageMakerEndpointConfiguration_ProductionVariants_routing(t *testing
})
}

func TestAccSageMakerEndpointConfiguration_ProductionVariants_emptyModel(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_sagemaker_endpoint_configuration.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.SageMakerServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckEndpointConfigurationDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccEndpointConfigurationConfig_emptyModel(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckEndpointConfigurationExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "production_variants.#", "1"),
resource.TestCheckResourceAttr(resourceName, "production_variants.0.model_name", ""),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
PreventPostDestroyRefresh: true,
// AWS does not return executionRoleArn in the DescribeEndpointConfig API response
ImportStateVerifyIgnore: []string{"execution_role_arn"},
},
},
})
}

func TestAccSageMakerEndpointConfiguration_ProductionVariants_serverless(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand Down Expand Up @@ -1376,6 +1407,26 @@ resource "aws_sagemaker_endpoint_configuration" "test" {
`, rName))
}

func testAccEndpointConfigurationConfig_emptyModel(rName string) string {
return acctest.ConfigCompose(testAccEndpointConfigurationConfig_base(rName), fmt.Sprintf(`

resource "aws_sagemaker_endpoint_configuration" "test" {
name = %[1]q

execution_role_arn = aws_iam_role.test.arn
production_variants {
variant_name = "variant-1"
initial_instance_count = 1
instance_type = "ml.g5.12xlarge"

routing_config {
routing_strategy = "LEAST_OUTSTANDING_REQUESTS"
}
}
}
`, rName))
}

func testAccEndpointConfigurationConfig_serverless(rName string) string {
return acctest.ConfigCompose(testAccEndpointConfigurationConfig_base(rName), fmt.Sprintf(`
resource "aws_sagemaker_endpoint_configuration" "test" {
Expand Down
Loading