From 444b2bf0606c6b8d22e194910ce8ffa7cb4ae28b Mon Sep 17 00:00:00 2001 From: Felipe Moreno <84039180+felipempda@users.noreply.github.com> Date: Thu, 25 Jul 2024 22:48:35 +0000 Subject: [PATCH 1/8] fix: typo r_studio_package_manager_url in sagemaker domain --- internal/service/sagemaker/domain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/sagemaker/domain.go b/internal/service/sagemaker/domain.go index aa6b85e64de..fa40d1f743d 100644 --- a/internal/service/sagemaker/domain.go +++ b/internal/service/sagemaker/domain.go @@ -1238,7 +1238,7 @@ func expandRStudioServerProDomainSettings(l []interface{}) *sagemaker.RStudioSer config.RStudioConnectUrl = aws.String(v) } - if v, ok := m["r_studio_packageManager_url"].(string); ok && v != "" { + if v, ok := m["r_studio_package_manager_url"].(string); ok && v != "" { config.RStudioPackageManagerUrl = aws.String(v) } From 914b99c86b11bf2a6a7e11f2dbe95f3141d0eb41 Mon Sep 17 00:00:00 2001 From: Felipe Moreno <84039180+felipempda@users.noreply.github.com> Date: Fri, 26 Jul 2024 03:11:07 +0000 Subject: [PATCH 2/8] fix: add testAccDomain_rStudioServerProAppSettings --- internal/service/sagemaker/domain_test.go | 120 ++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/internal/service/sagemaker/domain_test.go b/internal/service/sagemaker/domain_test.go index 2dfe9b1041b..351cf44d5ed 100644 --- a/internal/service/sagemaker/domain_test.go +++ b/internal/service/sagemaker/domain_test.go @@ -622,6 +622,38 @@ func testAccDomain_rStudioServerProAppSettings(t *testing.T) { }) } +func TestAccDomain_rStudioServerProDomainSettings(t *testing.T) { + ctx := acctest.Context(t) + var domain sagemaker.DescribeDomainOutput + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_sagemaker_domain.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.SageMakerServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckDomainDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccDomainConfig_rStudioServerProDomainSettings(rName, "https://connect.domain.com", "https://package.domain.com"), + Check: resource.ComposeTestCheckFunc( + testAccCheckDomainExists(ctx, resourceName, &domain), + resource.TestCheckResourceAttr(resourceName, "domain_settings.#", acctest.Ct1), + resource.TestCheckResourceAttr(resourceName, "domain_settings.0.r_studio_server_pro_domain_settings.#", acctest.Ct1), + resource.TestCheckResourceAttr(resourceName, "domain_settings.0.r_studio_server_pro_domain_settings.0.r_studio_connect_url", "https://connect.domain.com"), + resource.TestCheckResourceAttr(resourceName, "domain_settings.0.r_studio_server_pro_domain_settings.0.r_studio_package_manager_url", "https://package.domain.com"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"retention_policy"}, + }, + }, + }) +} + func testAccDomain_kernelGatewayAppSettings(t *testing.T) { ctx := acctest.Context(t) var domain sagemaker.DescribeDomainOutput @@ -1876,6 +1908,94 @@ resource "aws_sagemaker_domain" "test" { `, rName, state)) } +func testAccDomainConfig_rStudioServerProDomainSettings(rName, connectURL string, packageURL string) string { + return acctest.ConfigCompose(testAccDomainConfig_baseWithLicense(rName), fmt.Sprintf(` +resource "aws_sagemaker_domain" "test" { + domain_name = %[1]q + auth_mode = "IAM" + vpc_id = aws_vpc.test.id + subnet_ids = aws_subnet.test[*].id + + domain_settings { + + r_studio_server_pro_domain_settings { + r_studio_connect_url = %[2]q + r_studio_package_manager_url = %[3]q + domain_execution_role_arn = aws_iam_role.test.arn + default_resource_spec { + instance_type = "system" + } + } + } + + default_user_settings { + execution_role = aws_iam_role.test.arn + } + + retention_policy { + home_efs_file_system = "Delete" + } + + # ignoring default image + # it would be too hard to create the logic to find the default Rstudio image: https://docs.aws.amazon.com/sagemaker/latest/dg/rstudio-version.html + # it changes for every region + lifecycle { + ignore_changes = [ + domain_settings[0].r_studio_server_pro_domain_settings[0].default_resource_spec[0] + ] + } +} +`, rName, connectURL, packageURL)) +} + +func testAccDomainConfig_baseWithLicense(rName string) string { + return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(` +data "aws_partition" "current" {} + +resource "aws_iam_role" "test" { + name = %[1]q + path = "/" + assume_role_policy = data.aws_iam_policy_document.test.json + inline_policy { + name = "GetLicense" + policy = data.aws_iam_policy_document.license.json + } +} + +data "aws_iam_policy_document" "test" { + statement { + actions = ["sts:AssumeRole"] + + principals { + type = "Service" + identifiers = ["sagemaker.${data.aws_partition.current.dns_suffix}"] + } + } +} + +# needed for RStudio +data "aws_iam_policy_document" "license" { + statement { + sid = "ReadLicense" + effect = "Allow" + actions = [ + "license-manager:ExtendLicenseConsumption", + "license-manager:ListReceivedLicenses", + "license-manager:GetLicense", + "license-manager:CheckoutLicense", + "license-manager:CheckInLicense", + ] + resources = ["*"] + } +} + +resource "aws_iam_role_policy_attachment" "test" { + role = aws_iam_role.test.name + policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/AmazonSageMakerFullAccess" +} +`, rName)) +} + func testAccDomainConfig_codeEditorAppSettings(rName string) string { return acctest.ConfigCompose(testAccDomainConfig_base(rName), fmt.Sprintf(` resource "aws_sagemaker_domain" "test" { From 3af234bfb2e2b12cc97dae6c94c6ad4306e193ae Mon Sep 17 00:00:00 2001 From: Felipe Moreno <84039180+felipempda@users.noreply.github.com> Date: Fri, 26 Jul 2024 03:14:34 +0000 Subject: [PATCH 3/8] fix: add testAccDomain_rStudioServerProDomainSettings as serial --- internal/service/sagemaker/domain_test.go | 2 +- internal/service/sagemaker/sagemaker_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/service/sagemaker/domain_test.go b/internal/service/sagemaker/domain_test.go index 351cf44d5ed..0e2b1ca3205 100644 --- a/internal/service/sagemaker/domain_test.go +++ b/internal/service/sagemaker/domain_test.go @@ -622,7 +622,7 @@ func testAccDomain_rStudioServerProAppSettings(t *testing.T) { }) } -func TestAccDomain_rStudioServerProDomainSettings(t *testing.T) { +func testAccDomain_rStudioServerProDomainSettings(t *testing.T) { ctx := acctest.Context(t) var domain sagemaker.DescribeDomainOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) diff --git a/internal/service/sagemaker/sagemaker_test.go b/internal/service/sagemaker/sagemaker_test.go index b04b117ee75..36376fa5948 100644 --- a/internal/service/sagemaker/sagemaker_test.go +++ b/internal/service/sagemaker/sagemaker_test.go @@ -66,6 +66,7 @@ func TestAccSageMaker_serial(t *testing.T) { "domainSettings": testAccDomain_domainSettings, "rSessionAppSettings": testAccDomain_rSessionAppSettings, "rStudioServerProAppSettings": testAccDomain_rStudioServerProAppSettings, + "rStudioServerProDomainSettings": testAccDomain_rStudioServerProDomainSettings, "spaceSettingsKernelGatewayAppSettings": testAccDomain_spaceSettingsKernelGatewayAppSettings, "code": testAccDomain_jupyterServerAppSettings_code, "efs": testAccDomain_efs, From 853ce14df6c7cef47e30a1509784b5e1145abeef Mon Sep 17 00:00:00 2001 From: Felipe Moreno <84039180+felipempda@users.noreply.github.com> Date: Fri, 26 Jul 2024 03:21:00 +0000 Subject: [PATCH 4/8] chore: add changelog 38547 --- .changelog/38547.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/38547.txt diff --git a/.changelog/38547.txt b/.changelog/38547.txt new file mode 100644 index 00000000000..4373aafe37c --- /dev/null +++ b/.changelog/38547.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_sagemaker_domain: Fix missing r_studio_package_manager_url +``` \ No newline at end of file From b47329304a283e36603c5b23d7df4ad437601d18 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 1 Aug 2024 15:00:46 -0400 Subject: [PATCH 5/8] Tweak CHANGELOG entry. --- .changelog/38547.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/38547.txt b/.changelog/38547.txt index 4373aafe37c..5fcaf92d1b5 100644 --- a/.changelog/38547.txt +++ b/.changelog/38547.txt @@ -1,3 +1,3 @@ ```release-note:bug -resource/aws_sagemaker_domain: Fix missing r_studio_package_manager_url +resource/aws_sagemaker_domain: Properly send `domain_settings.r_studio_server_pro_domain_settings.r_studio_package_manager_url` argument on create ``` \ No newline at end of file From d5f9eecd22c67a175736fb4048871d8df2f9611c Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 1 Aug 2024 15:04:00 -0400 Subject: [PATCH 6/8] Fix terrafmt errors. --- internal/service/sagemaker/domain_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/service/sagemaker/domain_test.go b/internal/service/sagemaker/domain_test.go index 0e2b1ca3205..5b79ede3e91 100644 --- a/internal/service/sagemaker/domain_test.go +++ b/internal/service/sagemaker/domain_test.go @@ -1923,8 +1923,8 @@ resource "aws_sagemaker_domain" "test" { r_studio_package_manager_url = %[3]q domain_execution_role_arn = aws_iam_role.test.arn default_resource_spec { - instance_type = "system" - } + instance_type = "system" + } } } @@ -1941,8 +1941,8 @@ resource "aws_sagemaker_domain" "test" { # it changes for every region lifecycle { ignore_changes = [ - domain_settings[0].r_studio_server_pro_domain_settings[0].default_resource_spec[0] - ] + domain_settings[0].r_studio_server_pro_domain_settings[0].default_resource_spec[0] + ] } } `, rName, connectURL, packageURL)) From ce55b2414603568eb3b3994a5d24b7d2c22f0f14 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 1 Aug 2024 15:24:21 -0400 Subject: [PATCH 7/8] r/aws_sagemaker_domain: Skip acceptance tests with errors like 'ConfigurationError: Domain-level App [arn:aws:sagemaker:us-west-2:...:app/d-bejfwx765inu/domain-shared/RStudioServerPro/default] failed to start: [ResourceNotFoundError: No available licenses were found. Validate that a license for RStudio Workbench exists in AWS License Manager that is in Active state.]'. --- internal/service/sagemaker/sagemaker_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/service/sagemaker/sagemaker_test.go b/internal/service/sagemaker/sagemaker_test.go index 36376fa5948..db767b12870 100644 --- a/internal/service/sagemaker/sagemaker_test.go +++ b/internal/service/sagemaker/sagemaker_test.go @@ -19,6 +19,7 @@ func testAccErrorCheckSkip(t *testing.T) resource.ErrorCheckFunc { return acctest.ErrorCheckSkipMessagesContaining(t, "is not supported in region", "is not supported for the chosen region", + "No available licenses were found", ) } From ba0e0705f79446529a3a7cafb7fd83d45573ce3e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 1 Aug 2024 15:25:34 -0400 Subject: [PATCH 8/8] Fix terrafmt errors. --- internal/service/sagemaker/domain_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/sagemaker/domain_test.go b/internal/service/sagemaker/domain_test.go index 5b79ede3e91..c2152458258 100644 --- a/internal/service/sagemaker/domain_test.go +++ b/internal/service/sagemaker/domain_test.go @@ -1923,7 +1923,7 @@ resource "aws_sagemaker_domain" "test" { r_studio_package_manager_url = %[3]q domain_execution_role_arn = aws_iam_role.test.arn default_resource_spec { - instance_type = "system" + instance_type = "system" } } } @@ -1940,7 +1940,7 @@ resource "aws_sagemaker_domain" "test" { # it would be too hard to create the logic to find the default Rstudio image: https://docs.aws.amazon.com/sagemaker/latest/dg/rstudio-version.html # it changes for every region lifecycle { - ignore_changes = [ + ignore_changes = [ domain_settings[0].r_studio_server_pro_domain_settings[0].default_resource_spec[0] ] }