Skip to content

Commit 639f9d3

Browse files
committed
Add an acceptance test for space_settings.remote_access
1 parent 5110143 commit 639f9d3

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

internal/service/sagemaker/sagemaker_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func TestAccSageMaker_serial(t *testing.T) {
108108
"codeEditorAppSettings": testAccSpace_codeEditorAppSettings,
109109
"storageSettings": testAccSpace_storageSettings,
110110
"customFileSystem": testAccSpace_customFileSystem,
111+
"remoteAccess": testAccSpace_remoteAccess,
111112
},
112113
"UserProfile": {
113114
acctest.CtBasic: testAccUserProfile_basic,

internal/service/sagemaker/space_test.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/YakDriver/regexache"
1313
"github.com/aws/aws-sdk-go-v2/service/sagemaker"
14+
awstypes "github.com/aws/aws-sdk-go-v2/service/sagemaker/types"
1415
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1516
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1617
"github.com/hashicorp/terraform-plugin-testing/terraform"
@@ -408,6 +409,62 @@ func testAccSpace_jupyterServerAppSettings(t *testing.T) {
408409
})
409410
}
410411

412+
func testAccSpace_remoteAccess(t *testing.T) {
413+
ctx := acctest.Context(t)
414+
var domain sagemaker.DescribeSpaceOutput
415+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
416+
resourceName := "aws_sagemaker_space.test"
417+
418+
resource.Test(t, resource.TestCase{
419+
PreCheck: func() { acctest.PreCheck(ctx, t) },
420+
ErrorCheck: acctest.ErrorCheck(t, names.SageMakerServiceID),
421+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
422+
CheckDestroy: testAccCheckSpaceDestroy(ctx),
423+
Steps: []resource.TestStep{
424+
{
425+
Config: testAccSpaceConfig_remoteAccess(rName, string(awstypes.FeatureStatusEnabled)),
426+
Check: resource.ComposeTestCheckFunc(
427+
testAccCheckSpaceExists(ctx, resourceName, &domain),
428+
resource.TestCheckResourceAttr(resourceName, "space_settings.#", "1"),
429+
resource.TestCheckResourceAttr(resourceName, "space_settings.0.remote_access", string(awstypes.FeatureStatusEnabled)),
430+
),
431+
},
432+
{
433+
ResourceName: resourceName,
434+
ImportState: true,
435+
ImportStateVerify: true,
436+
},
437+
{
438+
// Set remote_access to DISABLED
439+
Config: testAccSpaceConfig_remoteAccess(rName, string(awstypes.FeatureStatusDisabled)),
440+
Check: resource.ComposeTestCheckFunc(
441+
testAccCheckSpaceExists(ctx, resourceName, &domain),
442+
resource.TestCheckResourceAttr(resourceName, "space_settings.#", "1"),
443+
resource.TestCheckResourceAttr(resourceName, "space_settings.0.remote_access", string(awstypes.FeatureStatusDisabled)),
444+
),
445+
},
446+
{
447+
// Set remote_access back to ENABLED
448+
Config: testAccSpaceConfig_remoteAccess(rName, string(awstypes.FeatureStatusEnabled)),
449+
Check: resource.ComposeTestCheckFunc(
450+
testAccCheckSpaceExists(ctx, resourceName, &domain),
451+
resource.TestCheckResourceAttr(resourceName, "space_settings.#", "1"),
452+
resource.TestCheckResourceAttr(resourceName, "space_settings.0.remote_access", string(awstypes.FeatureStatusEnabled)),
453+
),
454+
},
455+
{
456+
// Remove remote_access (inherit from the previous value)
457+
Config: testAccSpaceConfig_spaceSettingsEmpty(rName),
458+
Check: resource.ComposeTestCheckFunc(
459+
testAccCheckSpaceExists(ctx, resourceName, &domain),
460+
resource.TestCheckResourceAttr(resourceName, "space_settings.#", "1"),
461+
resource.TestCheckResourceAttr(resourceName, "space_settings.0.remote_access", string(awstypes.FeatureStatusEnabled)),
462+
),
463+
},
464+
},
465+
})
466+
}
467+
411468
func testAccSpace_disappears(t *testing.T) {
412469
ctx := acctest.Context(t)
413470
var domain sagemaker.DescribeSpaceOutput
@@ -830,3 +887,27 @@ resource "aws_sagemaker_space" "test" {
830887
}
831888
`, rName, baseImage))
832889
}
890+
891+
func testAccSpaceConfig_remoteAccess(rName, remoteAccess string) string {
892+
return acctest.ConfigCompose(testAccSpaceConfig_base(rName), fmt.Sprintf(`
893+
resource "aws_sagemaker_space" "test" {
894+
domain_id = aws_sagemaker_domain.test.id
895+
space_name = %[1]q
896+
897+
space_settings {
898+
remote_access = %[2]q
899+
}
900+
}
901+
`, rName, remoteAccess))
902+
}
903+
904+
func testAccSpaceConfig_spaceSettingsEmpty(rName string) string {
905+
return acctest.ConfigCompose(testAccSpaceConfig_base(rName), fmt.Sprintf(`
906+
resource "aws_sagemaker_space" "test" {
907+
domain_id = aws_sagemaker_domain.test.id
908+
space_name = %[1]q
909+
910+
space_settings {}
911+
}
912+
`, rName))
913+
}

0 commit comments

Comments
 (0)