diff --git a/.changelog/20711.txt b/.changelog/20711.txt new file mode 100644 index 00000000000..e0065817019 --- /dev/null +++ b/.changelog/20711.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_sagemaker_notebook_instance: Add `platform_identifier` argument +``` \ No newline at end of file diff --git a/aws/resource_aws_sagemaker_notebook_instance.go b/aws/resource_aws_sagemaker_notebook_instance.go index 7e829d9a809..bfd10409c12 100644 --- a/aws/resource_aws_sagemaker_notebook_instance.go +++ b/aws/resource_aws_sagemaker_notebook_instance.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + "regexp" "time" "github.com/aws/aws-sdk-go/aws" @@ -56,6 +57,15 @@ func resourceAwsSagemakerNotebookInstance() *schema.Resource { Required: true, ValidateFunc: validation.StringInSlice(sagemaker.InstanceType_Values(), false), }, + + "platform_identifier": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ValidateFunc: validation.StringMatch(regexp.MustCompile(`^(notebook-al1-v1|notebook-al2-v1)$`), ""), + }, + "additional_code_repositories": { Type: schema.TypeSet, Optional: true, @@ -147,6 +157,10 @@ func resourceAwsSagemakerNotebookInstanceCreate(d *schema.ResourceData, meta int createOpts.RootAccess = aws.String(v.(string)) } + if v, ok := d.GetOk("platform_identifier"); ok { + createOpts.PlatformIdentifier = aws.String(v.(string)) + } + if v, ok := d.GetOk("direct_internet_access"); ok { createOpts.DirectInternetAccess = aws.String(v.(string)) } @@ -226,6 +240,11 @@ func resourceAwsSagemakerNotebookInstanceRead(d *schema.ResourceData, meta inter if err := d.Set("instance_type", notebookInstance.InstanceType); err != nil { return fmt.Errorf("error setting instance_type for sagemaker notebook instance (%s): %s", d.Id(), err) } + + if err := d.Set("platform_identifier", notebookInstance.PlatformIdentifier); err != nil { + return fmt.Errorf("error setting platform_identifier for sagemaker notebook instance (%s): %s", d.Id(), err) + } + if err := d.Set("subnet_id", notebookInstance.SubnetId); err != nil { return fmt.Errorf("error setting subnet_id for sagemaker notebook instance (%s): %s", d.Id(), err) } diff --git a/aws/resource_aws_sagemaker_notebook_instance_test.go b/aws/resource_aws_sagemaker_notebook_instance_test.go index 6fc80c9c4cf..f2caf1789d4 100644 --- a/aws/resource_aws_sagemaker_notebook_instance_test.go +++ b/aws/resource_aws_sagemaker_notebook_instance_test.go @@ -92,6 +92,7 @@ func TestAccAWSSagemakerNotebookInstance_basic(t *testing.T) { testAccCheckAWSSagemakerNotebookInstanceExists(resourceName, ¬ebook), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "instance_type", "ml.t2.medium"), + resource.TestCheckResourceAttr(resourceName, "platform_identifier", "notebook-al1-v1"), resource.TestCheckResourceAttrPair(resourceName, "role_arn", "aws_iam_role.test", "arn"), resource.TestCheckResourceAttr(resourceName, "direct_internet_access", "Enabled"), resource.TestCheckResourceAttr(resourceName, "root_access", "Enabled"), @@ -435,6 +436,40 @@ func TestAccAWSSagemakerNotebookInstance_root_access(t *testing.T) { }) } +func TestAccAWSSagemakerNotebookInstance_platform_identifier(t *testing.T) { + var notebook sagemaker.DescribeNotebookInstanceOutput + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_sagemaker_notebook_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, sagemaker.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSSagemakerNotebookInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSSagemakerNotebookInstanceConfigPlatformIdentifier(rName, "notebook-al2-v1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSagemakerNotebookInstanceExists(resourceName, ¬ebook), + resource.TestCheckResourceAttr(resourceName, "platform_identifier", "notebook-al2-v1"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSSagemakerNotebookInstanceConfigPlatformIdentifier(rName, "notebook-al1-v1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSagemakerNotebookInstanceExists(resourceName, ¬ebook), + resource.TestCheckResourceAttr(resourceName, "platform_identifier", "notebook-al1-v1"), + ), + }, + }, + }) +} + func TestAccAWSSagemakerNotebookInstance_direct_internet_access(t *testing.T) { var notebook sagemaker.DescribeNotebookInstanceOutput rName := acctest.RandomWithPrefix("tf-acc-test") @@ -701,6 +736,16 @@ resource "aws_sagemaker_notebook_instance" "test" { `, rName, rootAccess) } +func testAccAWSSagemakerNotebookInstanceConfigPlatformIdentifier(rName string, platformIdentifier string) string { + return testAccAWSSagemakerNotebookInstanceBaseConfig(rName) + fmt.Sprintf(` +resource "aws_sagemaker_notebook_instance" "test" { + name = %[1]q + role_arn = aws_iam_role.test.arn + instance_type = "ml.t2.medium" + platform_identifier = %[2]q +} +`, rName, platformIdentifier) +} func testAccAWSSagemakerNotebookInstanceConfigDirectInternetAccess(rName string, directInternetAccess string) string { return testAccAWSSagemakerNotebookInstanceBaseConfig(rName) + fmt.Sprintf(` diff --git a/website/docs/r/sagemaker_notebook_instance.html.markdown b/website/docs/r/sagemaker_notebook_instance.html.markdown index e2157d38953..8a819c753d7 100644 --- a/website/docs/r/sagemaker_notebook_instance.html.markdown +++ b/website/docs/r/sagemaker_notebook_instance.html.markdown @@ -56,6 +56,7 @@ The following arguments are supported: * `name` - (Required) The name of the notebook instance (must be unique). * `role_arn` - (Required) The ARN of the IAM role to be used by the notebook instance which allows SageMaker to call other services on your behalf. * `instance_type` - (Required) The name of ML compute instance type. +* `platform_identifier` - (Optional) The platform identifier of the notebook instance runtime environment. This value can be either `notebook-al1-v1` or `notebook-al2-v1`, depending on which version of Amazon Linux you require. * `volume_size` - (Optional) The size, in GB, of the ML storage volume to attach to the notebook instance. The default value is 5 GB. * `subnet_id` - (Optional) The VPC subnet ID. * `security_groups` - (Optional) The associated security groups.