From d02d77883bd1f697a95c9b545b2c46c375e6835e Mon Sep 17 00:00:00 2001 From: Holly Evans <39742776+holly-evans@users.noreply.github.com> Date: Sat, 3 Jun 2023 20:12:44 -0500 Subject: [PATCH 01/12] Add model_package_name for aws_sagemaker_model --- internal/service/sagemaker/model.go | 34 ++++++++-- internal/service/sagemaker/model_test.go | 68 ++++++++++++++++++++ website/docs/r/sagemaker_model.html.markdown | 3 +- 3 files changed, 98 insertions(+), 7 deletions(-) diff --git a/internal/service/sagemaker/model.go b/internal/service/sagemaker/model.go index ab8c9ff48ca..c9ac6466fb5 100644 --- a/internal/service/sagemaker/model.go +++ b/internal/service/sagemaker/model.go @@ -59,7 +59,7 @@ func ResourceModel() *schema.Resource { }, "image": { Type: schema.TypeString, - Required: true, + Optional: true, ForceNew: true, ValidateFunc: validImage, }, @@ -106,6 +106,12 @@ func ResourceModel() *schema.Resource { ForceNew: true, ValidateFunc: validModelDataURL, }, + "model_package_name": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: verify.ValidARN, + }, }, }, }, @@ -164,7 +170,7 @@ func ResourceModel() *schema.Resource { }, "image": { Type: schema.TypeString, - Required: true, + Optional: true, ForceNew: true, ValidateFunc: validImage, }, @@ -211,6 +217,12 @@ func ResourceModel() *schema.Resource { ForceNew: true, ValidateFunc: validModelDataURL, }, + "model_package_name": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: verify.ValidARN, + }, }, }, }, @@ -404,8 +416,10 @@ func resourceModelDelete(ctx context.Context, d *schema.ResourceData, meta inter } func expandContainer(m map[string]interface{}) *sagemaker.ContainerDefinition { - container := sagemaker.ContainerDefinition{ - Image: aws.String(m["image"].(string)), + container := sagemaker.ContainerDefinition{} + + if v, ok := m["image"]; ok && v.(string) != "" { + container.Image = aws.String(v.(string)) } if v, ok := m["mode"]; ok && v.(string) != "" { @@ -418,6 +432,9 @@ func expandContainer(m map[string]interface{}) *sagemaker.ContainerDefinition { if v, ok := m["model_data_url"]; ok && v.(string) != "" { container.ModelDataUrl = aws.String(v.(string)) } + if v, ok := m["model_package_name"]; ok && v.(string) != "" { + container.ModelPackageName = aws.String(v.(string)) + } if v, ok := m["environment"].(map[string]interface{}); ok && len(v) > 0 { container.Environment = flex.ExpandStringMap(v) } @@ -477,8 +494,10 @@ func flattenContainer(container *sagemaker.ContainerDefinition) []interface{} { } cfg := make(map[string]interface{}) - - cfg["image"] = aws.StringValue(container.Image) + + if container.Image != nil { + cfg["image"] = aws.StringValue(container.Image) + } if container.Mode != nil { cfg["mode"] = aws.StringValue(container.Mode) @@ -490,6 +509,9 @@ func flattenContainer(container *sagemaker.ContainerDefinition) []interface{} { if container.ModelDataUrl != nil { cfg["model_data_url"] = aws.StringValue(container.ModelDataUrl) } + if container.ModelPackageName != nil { + cfg["model_package_name"] = aws.StringValue(container.ModelPackageName) + } if container.Environment != nil { cfg["environment"] = aws.StringValueMap(container.Environment) } diff --git a/internal/service/sagemaker/model_test.go b/internal/service/sagemaker/model_test.go index afcc3ccf031..1f5dd840f21 100644 --- a/internal/service/sagemaker/model_test.go +++ b/internal/service/sagemaker/model_test.go @@ -262,6 +262,33 @@ func TestAccSageMakerModel_primaryContainerModeSingle(t *testing.T) { }) } +func TestAccSageMakerModel_primaryContainerModelPackageName(t *testing.T) { + ctx := acctest.Context(t) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_sagemaker_model.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, sagemaker.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckModelDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccModelConfig_primaryContainerPackageName(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckModelExists(ctx, resourceName), + resource.TestCheckResourceAttrSet(resourceName, "primary_container.0.model_package_name"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccSageMakerModel_containers(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -618,6 +645,47 @@ resource "aws_s3_object" "test" { `, rName)) } +func testAccModelConfig_primaryContainerPackageName(rName string) string { + return acctest.ConfigCompose(testAccModelConfigBase(rName), fmt.Sprintf(` +data "aws_region" "current" {} + +locals { + region_account_map = { + us-east-1 = "865070037744" + us-east-2 = "057799348421" + us-west-1 = "382657785993" + us-west-2 = "594846645681" + ca-central-1 = "470592106596" + eu-central-1 = "446921602837" + eu-west-1 = "985815980388" + eu-west-2 = "856760150666" + eu-west-3 = "843114510376" + eu-north-1 = "136758871317" + ap-southeast-1 = "192199979996" + ap-southeast-2 = "666831318237" + ap-northeast-2 = "745090734665" + ap-northeast-1 = "977537786026" + ap-south-1 = "077584701553" + sa-east-1 = "270155090741" + } + account = region_account_map[data.aws_region.current] + model_package_name = format( + "arn:aws:sagemaker:%%s:%%s:model-package/gpt-2-1584040650-de7f6ab78d68d7fdf5f4f39a559d05ac", + data.aws_region.current, + account + ) +} + +resource "aws_sagemaker_model" "test" { + name = %[1]q + execution_role_arn = aws_iam_role.test.arn + primary_container { + model_package_name = local.model_package_name + } +} +`, rName)) +} + func testAccModelConfig_primaryContainerHostname(rName string) string { return acctest.ConfigCompose(testAccModelConfigBase(rName), fmt.Sprintf(` resource "aws_sagemaker_model" "test" { diff --git a/website/docs/r/sagemaker_model.html.markdown b/website/docs/r/sagemaker_model.html.markdown index 1d581d96f49..1737a5f4dec 100644 --- a/website/docs/r/sagemaker_model.html.markdown +++ b/website/docs/r/sagemaker_model.html.markdown @@ -59,9 +59,10 @@ The following arguments are supported: The `primary_container` and `container` block both support: -* `image` - (Required) The registry path where the inference code image is stored in Amazon ECR. +* `image` - (optional) The registry path where the inference code image is stored in Amazon ECR. * `mode` - (Optional) The container hosts value `SingleModel/MultiModel`. The default value is `SingleModel`. * `model_data_url` - (Optional) The URL for the S3 location where model artifacts are stored. +* `model_package_name` - (Optional) The Amazon Resource Name (ARN) of the model package to use to create the model. * `container_hostname` - (Optional) The DNS host name for the container. * `environment` - (Optional) Environment variables for the Docker container. A list of key value pairs. From a0ad2d1e156ee17e9a161a9aae5158b66fb4b46f Mon Sep 17 00:00:00 2001 From: Holly Evans <39742776+holly-evans@users.noreply.github.com> Date: Sat, 3 Jun 2023 20:27:49 -0500 Subject: [PATCH 02/12] Format --- internal/service/sagemaker/model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/sagemaker/model.go b/internal/service/sagemaker/model.go index c9ac6466fb5..00307ce3cf9 100644 --- a/internal/service/sagemaker/model.go +++ b/internal/service/sagemaker/model.go @@ -494,7 +494,7 @@ func flattenContainer(container *sagemaker.ContainerDefinition) []interface{} { } cfg := make(map[string]interface{}) - + if container.Image != nil { cfg["image"] = aws.StringValue(container.Image) } From 911216f7e7ff4a6c99df739548f2a1bef9bbd626 Mon Sep 17 00:00:00 2001 From: Holly Evans <39742776+holly-evans@users.noreply.github.com> Date: Sat, 3 Jun 2023 20:48:42 -0500 Subject: [PATCH 03/12] Formatting --- website/docs/r/sagemaker_model.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/sagemaker_model.html.markdown b/website/docs/r/sagemaker_model.html.markdown index 1737a5f4dec..1889ac38b0f 100644 --- a/website/docs/r/sagemaker_model.html.markdown +++ b/website/docs/r/sagemaker_model.html.markdown @@ -59,7 +59,7 @@ The following arguments are supported: The `primary_container` and `container` block both support: -* `image` - (optional) The registry path where the inference code image is stored in Amazon ECR. +* `image` - (Optional) The registry path where the inference code image is stored in Amazon ECR. * `mode` - (Optional) The container hosts value `SingleModel/MultiModel`. The default value is `SingleModel`. * `model_data_url` - (Optional) The URL for the S3 location where model artifacts are stored. * `model_package_name` - (Optional) The Amazon Resource Name (ARN) of the model package to use to create the model. From 7ad58daee81c66d03ad9c3aab855fcc5c549dcae Mon Sep 17 00:00:00 2001 From: Holly Evans <39742776+holly-evans@users.noreply.github.com> Date: Sat, 3 Jun 2023 20:51:27 -0500 Subject: [PATCH 04/12] Add changelog --- .changelog/31755.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/31755.txt diff --git a/.changelog/31755.txt b/.changelog/31755.txt new file mode 100644 index 00000000000..512d0894a40 --- /dev/null +++ b/.changelog/31755.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_sagemaker_model: Add model_package_name argument +``` \ No newline at end of file From 4dcf1f9c2a7a7378b2385f4fd73f9ee12bdab6c1 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 5 Jun 2023 07:57:26 -0400 Subject: [PATCH 05/12] Update .changelog/31755.txt Co-authored-by: Bruno Schaatsbergen <58337159+bschaatsbergen@users.noreply.github.com> --- .changelog/31755.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/31755.txt b/.changelog/31755.txt index 512d0894a40..f818244dec8 100644 --- a/.changelog/31755.txt +++ b/.changelog/31755.txt @@ -1,3 +1,3 @@ ```release-note:enhancement -resource/aws_sagemaker_model: Add model_package_name argument +resource/aws_sagemaker_model: Add `model_package_name` argument ``` \ No newline at end of file From 371b62f210d8b553e0c722a588c7da3555c7477f Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 5 Jun 2023 08:00:49 -0400 Subject: [PATCH 06/12] Fix terrafmt errors in acceptance test configurations. --- internal/service/sagemaker/model_test.go | 51 +++++++++++++----------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/internal/service/sagemaker/model_test.go b/internal/service/sagemaker/model_test.go index 1f5dd840f21..4ab16fd5502 100644 --- a/internal/service/sagemaker/model_test.go +++ b/internal/service/sagemaker/model_test.go @@ -650,35 +650,38 @@ func testAccModelConfig_primaryContainerPackageName(rName string) string { data "aws_region" "current" {} locals { - region_account_map = { - us-east-1 = "865070037744" - us-east-2 = "057799348421" - us-west-1 = "382657785993" - us-west-2 = "594846645681" - ca-central-1 = "470592106596" - eu-central-1 = "446921602837" - eu-west-1 = "985815980388" - eu-west-2 = "856760150666" - eu-west-3 = "843114510376" - eu-north-1 = "136758871317" - ap-southeast-1 = "192199979996" - ap-southeast-2 = "666831318237" - ap-northeast-2 = "745090734665" - ap-northeast-1 = "977537786026" - ap-south-1 = "077584701553" - sa-east-1 = "270155090741" - } - account = region_account_map[data.aws_region.current] - model_package_name = format( - "arn:aws:sagemaker:%%s:%%s:model-package/gpt-2-1584040650-de7f6ab78d68d7fdf5f4f39a559d05ac", - data.aws_region.current, - account - ) + region_account_map = { + us-east-1 = "865070037744" + us-east-2 = "057799348421" + us-west-1 = "382657785993" + us-west-2 = "594846645681" + ca-central-1 = "470592106596" + eu-central-1 = "446921602837" + eu-west-1 = "985815980388" + eu-west-2 = "856760150666" + eu-west-3 = "843114510376" + eu-north-1 = "136758871317" + ap-southeast-1 = "192199979996" + ap-southeast-2 = "666831318237" + ap-northeast-2 = "745090734665" + ap-northeast-1 = "977537786026" + ap-south-1 = "077584701553" + sa-east-1 = "270155090741" + } + + account = region_account_map[data.aws_region.current] + + model_package_name = format( + "arn:aws:sagemaker:%%s:%%s:model-package/gpt-2-1584040650-de7f6ab78d68d7fdf5f4f39a559d05ac", + data.aws_region.current, + account + ) } resource "aws_sagemaker_model" "test" { name = %[1]q execution_role_arn = aws_iam_role.test.arn + primary_container { model_package_name = local.model_package_name } From aeb1e6c106d7ddd1af080681caac1a7eb22ddf58 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 5 Jun 2023 08:02:43 -0400 Subject: [PATCH 07/12] Tweak CHANGELOG entry. --- .changelog/31755.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/31755.txt b/.changelog/31755.txt index f818244dec8..4bcd501601b 100644 --- a/.changelog/31755.txt +++ b/.changelog/31755.txt @@ -1,3 +1,3 @@ ```release-note:enhancement -resource/aws_sagemaker_model: Add `model_package_name` argument +resource/aws_sagemaker_model: Add `container.model_package_name` and `primary_container.model_package_name` arguments ``` \ No newline at end of file From 332ef6f005d292ded6bc855a3904adab0d1c1b1e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 5 Jun 2023 08:06:58 -0400 Subject: [PATCH 08/12] Fix providerlint 'AWSAT003' and 'AWSAT005'. --- internal/service/sagemaker/model_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/service/sagemaker/model_test.go b/internal/service/sagemaker/model_test.go index 4ab16fd5502..63e1d36ec16 100644 --- a/internal/service/sagemaker/model_test.go +++ b/internal/service/sagemaker/model_test.go @@ -645,6 +645,7 @@ resource "aws_s3_object" "test" { `, rName)) } +// lintignore:AWSAT003,AWSAT005 func testAccModelConfig_primaryContainerPackageName(rName string) string { return acctest.ConfigCompose(testAccModelConfigBase(rName), fmt.Sprintf(` data "aws_region" "current" {} From 469849522949cd24ca684ea383cdd17faab88089 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 5 Jun 2023 08:11:35 -0400 Subject: [PATCH 09/12] r/aws_sagemaker_model: Tidy up acceptance test configurations. --- internal/service/sagemaker/model_test.go | 100 +++++------------------ 1 file changed, 21 insertions(+), 79 deletions(-) diff --git a/internal/service/sagemaker/model_test.go b/internal/service/sagemaker/model_test.go index 63e1d36ec16..0172ab08d15 100644 --- a/internal/service/sagemaker/model_test.go +++ b/internal/service/sagemaker/model_test.go @@ -476,7 +476,7 @@ func testAccCheckModelExists(ctx context.Context, n string) resource.TestCheckFu } } -func testAccModelConfigBase(rName string) string { +func testAccModelConfig_base(rName string) string { return fmt.Sprintf(` resource "aws_iam_role" "test" { name = %[1]q @@ -502,7 +502,7 @@ data "aws_sagemaker_prebuilt_ecr_image" "test" { } func testAccModelConfig_basic(rName string) string { - return acctest.ConfigCompose(testAccModelConfigBase(rName), fmt.Sprintf(` + return acctest.ConfigCompose(testAccModelConfig_base(rName), fmt.Sprintf(` resource "aws_sagemaker_model" "test" { name = %[1]q execution_role_arn = aws_iam_role.test.arn @@ -515,7 +515,7 @@ resource "aws_sagemaker_model" "test" { } func testAccModelConfig_inferenceExecution(rName string) string { - return acctest.ConfigCompose(testAccModelConfigBase(rName), fmt.Sprintf(` + return acctest.ConfigCompose(testAccModelConfig_base(rName), fmt.Sprintf(` resource "aws_sagemaker_model" "test" { name = %[1]q execution_role_arn = aws_iam_role.test.arn @@ -536,7 +536,7 @@ resource "aws_sagemaker_model" "test" { } func testAccModelConfig_tags1(rName, tagKey1, tagValue1 string) string { - return acctest.ConfigCompose(testAccModelConfigBase(rName), fmt.Sprintf(` + return acctest.ConfigCompose(testAccModelConfig_base(rName), fmt.Sprintf(` resource "aws_sagemaker_model" "test" { name = %[1]q execution_role_arn = aws_iam_role.test.arn @@ -553,7 +553,7 @@ resource "aws_sagemaker_model" "test" { } func testAccModelConfig_tags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { - return acctest.ConfigCompose(testAccModelConfigBase(rName), fmt.Sprintf(` + return acctest.ConfigCompose(testAccModelConfig_base(rName), fmt.Sprintf(` resource "aws_sagemaker_model" "test" { name = %[1]q execution_role_arn = aws_iam_role.test.arn @@ -571,7 +571,7 @@ resource "aws_sagemaker_model" "test" { } func testAccModelConfig_primaryContainerDataURL(rName string) string { - return acctest.ConfigCompose(testAccModelConfigBase(rName), fmt.Sprintf(` + return acctest.ConfigCompose(testAccModelConfig_base(rName), fmt.Sprintf(` resource "aws_sagemaker_model" "test" { name = %[1]q execution_role_arn = aws_iam_role.test.arn @@ -632,11 +632,6 @@ resource "aws_s3_bucket" "test" { force_destroy = true } -resource "aws_s3_bucket_acl" "test" { - bucket = aws_s3_bucket.test.id - acl = "private" -} - resource "aws_s3_object" "test" { bucket = aws_s3_bucket.test.bucket key = "model.tar.gz" @@ -647,7 +642,7 @@ resource "aws_s3_object" "test" { // lintignore:AWSAT003,AWSAT005 func testAccModelConfig_primaryContainerPackageName(rName string) string { - return acctest.ConfigCompose(testAccModelConfigBase(rName), fmt.Sprintf(` + return acctest.ConfigCompose(testAccModelConfig_base(rName), fmt.Sprintf(` data "aws_region" "current" {} locals { @@ -691,7 +686,7 @@ resource "aws_sagemaker_model" "test" { } func testAccModelConfig_primaryContainerHostname(rName string) string { - return acctest.ConfigCompose(testAccModelConfigBase(rName), fmt.Sprintf(` + return acctest.ConfigCompose(testAccModelConfig_base(rName), fmt.Sprintf(` resource "aws_sagemaker_model" "test" { name = %[1]q execution_role_arn = aws_iam_role.test.arn @@ -705,7 +700,7 @@ resource "aws_sagemaker_model" "test" { } func testAccModelConfig_primaryContainerImage(rName string) string { - return acctest.ConfigCompose(testAccModelConfigBase(rName), fmt.Sprintf(` + return acctest.ConfigCompose(testAccModelConfig_base(rName), fmt.Sprintf(` resource "aws_sagemaker_model" "test" { name = %[1]q execution_role_arn = aws_iam_role.test.arn @@ -722,7 +717,7 @@ resource "aws_sagemaker_model" "test" { } func testAccModelConfig_primaryContainerEnvironment(rName string) string { - return acctest.ConfigCompose(testAccModelConfigBase(rName), fmt.Sprintf(` + return acctest.ConfigCompose(testAccModelConfig_base(rName), fmt.Sprintf(` resource "aws_sagemaker_model" "test" { name = %[1]q execution_role_arn = aws_iam_role.test.arn @@ -739,7 +734,7 @@ resource "aws_sagemaker_model" "test" { } func testAccModelConfig_primaryContainerModeSingle(rName string) string { - return acctest.ConfigCompose(testAccModelConfigBase(rName), fmt.Sprintf(` + return acctest.ConfigCompose(testAccModelConfig_base(rName), fmt.Sprintf(` resource "aws_sagemaker_model" "test" { name = %[1]q execution_role_arn = aws_iam_role.test.arn @@ -753,7 +748,7 @@ resource "aws_sagemaker_model" "test" { } func testAccModelConfig_containers(rName string) string { - return acctest.ConfigCompose(testAccModelConfigBase(rName), fmt.Sprintf(` + return acctest.ConfigCompose(testAccModelConfig_base(rName), fmt.Sprintf(` resource "aws_sagemaker_model" "test" { name = %[1]q execution_role_arn = aws_iam_role.test.arn @@ -770,7 +765,7 @@ resource "aws_sagemaker_model" "test" { } func testAccModelConfig_networkIsolation(rName string) string { - return acctest.ConfigCompose(testAccModelConfigBase(rName), fmt.Sprintf(` + return acctest.ConfigCompose(testAccModelConfig_base(rName), fmt.Sprintf(` resource "aws_sagemaker_model" "test" { name = %[1]q execution_role_arn = aws_iam_role.test.arn @@ -784,7 +779,7 @@ resource "aws_sagemaker_model" "test" { } func testAccModelConfig_vpcBasic(rName string) string { - return acctest.ConfigCompose(testAccModelConfigBase(rName), acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` + return acctest.ConfigCompose(testAccModelConfig_base(rName), acctest.ConfigVPCWithSubnets(rName, 2), fmt.Sprintf(` resource "aws_sagemaker_model" "test" { name = %[1]q execution_role_arn = aws_iam_role.test.arn @@ -795,50 +790,15 @@ resource "aws_sagemaker_model" "test" { } vpc_config { - subnets = [aws_subnet.test.id, aws_subnet.bar.id] - security_group_ids = [aws_security_group.test.id, aws_security_group.bar.id] - } -} - -resource "aws_vpc" "test" { - cidr_block = "10.1.0.0/16" - - tags = { - Name = %[1]q - } -} - -resource "aws_subnet" "test" { - cidr_block = "10.1.1.0/24" - availability_zone = data.aws_availability_zones.available.names[0] - vpc_id = aws_vpc.test.id - - tags = { - Name = %[1]q - } -} - -resource "aws_subnet" "bar" { - cidr_block = "10.1.2.0/24" - availability_zone = data.aws_availability_zones.available.names[0] - vpc_id = aws_vpc.test.id - - tags = { - Name = %[1]q + subnets = aws_subnet.test[*].id + security_group_ids = aws_security_group.test[*].id } } resource "aws_security_group" "test" { - name = "%[1]s-1" - vpc_id = aws_vpc.test.id - - tags = { - Name = %[1]q - } -} + count = 2 -resource "aws_security_group" "bar" { - name = "%[1]s-2" + name = "%[1]s-${count.index}" vpc_id = aws_vpc.test.id tags = { @@ -850,7 +810,7 @@ resource "aws_security_group" "bar" { // lintignore:AWSAT003,AWSAT005 func testAccModelConfig_primaryContainerPrivateDockerRegistry(rName string) string { - return acctest.ConfigCompose(testAccModelConfigBase(rName), acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` + return acctest.ConfigCompose(testAccModelConfig_base(rName), acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(` resource "aws_sagemaker_model" "test" { name = %[1]q execution_role_arn = aws_iam_role.test.arn @@ -869,31 +829,13 @@ resource "aws_sagemaker_model" "test" { } vpc_config { - subnets = [aws_subnet.test.id] + subnets = aws_subnet.test[*].id security_group_ids = [aws_security_group.test.id] } } -resource "aws_vpc" "test" { - cidr_block = "10.1.0.0/16" - - tags = { - Name = %[1]q - } -} - -resource "aws_subnet" "test" { - cidr_block = "10.1.1.0/24" - availability_zone = data.aws_availability_zones.available.names[0] - vpc_id = aws_vpc.test.id - - tags = { - Name = %[1]q - } -} - resource "aws_security_group" "test" { - name = "%[1]s-1" + name = %[1]q vpc_id = aws_vpc.test.id tags = { From 7baa7ac879d9b1286309b783869240a7ce726d34 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 5 Jun 2023 08:20:06 -0400 Subject: [PATCH 10/12] Fix acceptance test configuration. --- internal/service/sagemaker/model_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/service/sagemaker/model_test.go b/internal/service/sagemaker/model_test.go index 0172ab08d15..052c8517aa7 100644 --- a/internal/service/sagemaker/model_test.go +++ b/internal/service/sagemaker/model_test.go @@ -665,12 +665,12 @@ locals { sa-east-1 = "270155090741" } - account = region_account_map[data.aws_region.current] + account = local.region_account_map[data.aws_region.current.name] model_package_name = format( "arn:aws:sagemaker:%%s:%%s:model-package/gpt-2-1584040650-de7f6ab78d68d7fdf5f4f39a559d05ac", - data.aws_region.current, - account + data.aws_region.current.name, + local.account ) } From 751f1587748fe039ebf1f83d990ad3fd7712934e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 5 Jun 2023 08:39:33 -0400 Subject: [PATCH 11/12] TestAccSageMakerModel_primaryContainerModelPackageName: Use model that we have a subscription for. --- internal/service/sagemaker/model_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/sagemaker/model_test.go b/internal/service/sagemaker/model_test.go index 052c8517aa7..13123420d4a 100644 --- a/internal/service/sagemaker/model_test.go +++ b/internal/service/sagemaker/model_test.go @@ -668,7 +668,7 @@ locals { account = local.region_account_map[data.aws_region.current.name] model_package_name = format( - "arn:aws:sagemaker:%%s:%%s:model-package/gpt-2-1584040650-de7f6ab78d68d7fdf5f4f39a559d05ac", + "arn:aws:sagemaker:%%s:%%s:model-package/hf-textgeneration-gpt2-cpu-b73b575105d336b680d151277ebe4ee0", data.aws_region.current.name, local.account ) From de8b90af036d3c248cc132f9dce1aa5c49216ae1 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 5 Jun 2023 08:44:53 -0400 Subject: [PATCH 12/12] Fix 'Error: creating SageMaker model: ValidationException: EnableNetworkIsolation must be set to true for using a product from AWS Marketplace'. --- internal/service/sagemaker/model_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/service/sagemaker/model_test.go b/internal/service/sagemaker/model_test.go index 13123420d4a..6c57b9cca90 100644 --- a/internal/service/sagemaker/model_test.go +++ b/internal/service/sagemaker/model_test.go @@ -675,8 +675,9 @@ locals { } resource "aws_sagemaker_model" "test" { - name = %[1]q - execution_role_arn = aws_iam_role.test.arn + name = %[1]q + enable_network_isolation = true + execution_role_arn = aws_iam_role.test.arn primary_container { model_package_name = local.model_package_name