From 82093f89ceb16ca01f2ca4a353c644f6ea457cec Mon Sep 17 00:00:00 2001 From: nikhil Date: Thu, 8 Oct 2020 19:45:24 +0530 Subject: [PATCH 1/3] f/aws_sagemaker_notebook_instance: Volume size --- ...esource_aws_sagemaker_notebook_instance.go | 19 +++++++++++++++++++ .../sagemaker_notebook_instance.html.markdown | 1 + 2 files changed, 20 insertions(+) diff --git a/aws/resource_aws_sagemaker_notebook_instance.go b/aws/resource_aws_sagemaker_notebook_instance.go index b19a180e230..7afdffa8465 100644 --- a/aws/resource_aws_sagemaker_notebook_instance.go +++ b/aws/resource_aws_sagemaker_notebook_instance.go @@ -46,6 +46,12 @@ func resourceAwsSagemakerNotebookInstance() *schema.Resource { Required: true, }, + "volume_size": { + Type: schema.TypeInt, + Optional: true, + Default: 5, + }, + "subnet_id": { Type: schema.TypeString, Optional: true, @@ -123,6 +129,10 @@ func resourceAwsSagemakerNotebookInstanceCreate(d *schema.ResourceData, meta int createOpts.SubnetId = aws.String(s.(string)) } + if v, ok := d.GetOk("volume_size"); ok { + createOpts.VolumeSizeInGB = aws.Int64(int64(v.(int))) + } + if k, ok := d.GetOk("kms_key_id"); ok { createOpts.KmsKeyId = aws.String(k.(string)) } @@ -200,6 +210,10 @@ func resourceAwsSagemakerNotebookInstanceRead(d *schema.ResourceData, meta inter return fmt.Errorf("error setting kms_key_id for sagemaker notebook instance (%s): %s", d.Id(), err) } + if err := d.Set("volume_size", notebookInstance.VolumeSizeInGB); err != nil { + return fmt.Errorf("error setting volume_size for sagemaker notebook instance (%s): %s", d.Id(), err) + } + if err := d.Set("lifecycle_config_name", notebookInstance.NotebookInstanceLifecycleConfigName); err != nil { return fmt.Errorf("error setting lifecycle_config_name for sagemaker notebook instance (%s): %s", d.Id(), err) } @@ -256,6 +270,11 @@ func resourceAwsSagemakerNotebookInstanceUpdate(d *schema.ResourceData, meta int hasChanged = true } + if d.HasChange("volume_size") { + updateOpts.VolumeSizeInGB = aws.Int64(int64(d.Get("volume_size").(int))) + hasChanged = true + } + if hasChanged { // Stop notebook diff --git a/website/docs/r/sagemaker_notebook_instance.html.markdown b/website/docs/r/sagemaker_notebook_instance.html.markdown index 451dd18109f..18fd55fec6f 100644 --- a/website/docs/r/sagemaker_notebook_instance.html.markdown +++ b/website/docs/r/sagemaker_notebook_instance.html.markdown @@ -33,6 +33,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. +* `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. * `kms_key_id` - (Optional) The AWS Key Management Service (AWS KMS) key that Amazon SageMaker uses to encrypt the model artifacts at rest using Amazon S3 server-side encryption. From 175dcf682f485a09ac6b8aa0c7f3e874c531751e Mon Sep 17 00:00:00 2001 From: nikhil Date: Mon, 12 Oct 2020 21:46:57 +0530 Subject: [PATCH 2/3] f/aws_sagemaker_notebook_instance: Volume size --- aws/resource_aws_sagemaker_notebook_instance_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/aws/resource_aws_sagemaker_notebook_instance_test.go b/aws/resource_aws_sagemaker_notebook_instance_test.go index 417c1089dfa..f2a4c9768ae 100644 --- a/aws/resource_aws_sagemaker_notebook_instance_test.go +++ b/aws/resource_aws_sagemaker_notebook_instance_test.go @@ -123,6 +123,8 @@ func TestAccAWSSagemakerNotebookInstance_update(t *testing.T) { resource.TestCheckResourceAttr( "aws_sagemaker_notebook_instance.foo", "instance_type", "ml.t2.medium"), + resource.TestCheckResourceAttr( + "aws_sagemaker_notebook_instance.foo", "volume_size", "5"), ), }, @@ -133,6 +135,8 @@ func TestAccAWSSagemakerNotebookInstance_update(t *testing.T) { resource.TestCheckResourceAttr( "aws_sagemaker_notebook_instance.foo", "instance_type", "ml.m4.xlarge"), + resource.TestCheckResourceAttr( + "aws_sagemaker_notebook_instance.foo", "volume_size", "8"), ), }, { @@ -472,6 +476,7 @@ resource "aws_sagemaker_notebook_instance" "foo" { name = "%s" role_arn = aws_iam_role.foo.arn instance_type = "ml.m4.xlarge" + volume_size = "8" } resource "aws_iam_role" "foo" { From 4054dda6594783976b76e7c39f1b57a7b2ee75ac Mon Sep 17 00:00:00 2001 From: nikhil Date: Mon, 12 Oct 2020 23:01:45 +0530 Subject: [PATCH 3/3] f/aws_sagemaker_notebook_instance: Volume size --- ...ce_aws_sagemaker_notebook_instance_test.go | 67 ++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/aws/resource_aws_sagemaker_notebook_instance_test.go b/aws/resource_aws_sagemaker_notebook_instance_test.go index f2a4c9768ae..9f820f9ff04 100644 --- a/aws/resource_aws_sagemaker_notebook_instance_test.go +++ b/aws/resource_aws_sagemaker_notebook_instance_test.go @@ -96,6 +96,8 @@ func TestAccAWSSagemakerNotebookInstance_basic(t *testing.T) { resource.TestCheckResourceAttr( "aws_sagemaker_notebook_instance.foo", "name", notebookName), + resource.TestCheckResourceAttr( + "aws_sagemaker_notebook_instance.foo", "volume_size", "5"), ), }, { @@ -123,8 +125,6 @@ func TestAccAWSSagemakerNotebookInstance_update(t *testing.T) { resource.TestCheckResourceAttr( "aws_sagemaker_notebook_instance.foo", "instance_type", "ml.t2.medium"), - resource.TestCheckResourceAttr( - "aws_sagemaker_notebook_instance.foo", "volume_size", "5"), ), }, @@ -135,6 +135,41 @@ func TestAccAWSSagemakerNotebookInstance_update(t *testing.T) { resource.TestCheckResourceAttr( "aws_sagemaker_notebook_instance.foo", "instance_type", "ml.m4.xlarge"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAWSSagemakerNotebookInstance_volumesize(t *testing.T) { + var notebook sagemaker.DescribeNotebookInstanceOutput + notebookName := resource.PrefixedUniqueId(sagemakerTestAccSagemakerNotebookInstanceResourceNamePrefix) + var resourceName = "aws_sagemaker_notebook_instance.foo" + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSSagemakerNotebookInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSSagemakerNotebookInstanceConfigVolume(notebookName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSagemakerNotebookInstanceExists(resourceName, ¬ebook), + + resource.TestCheckResourceAttr( + "aws_sagemaker_notebook_instance.foo", "volume_size", "5"), + ), + }, + + { + Config: testAccAWSSagemakerNotebookInstanceUpdateConfig(notebookName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSSagemakerNotebookInstanceExists("aws_sagemaker_notebook_instance.foo", ¬ebook), + resource.TestCheckResourceAttr( "aws_sagemaker_notebook_instance.foo", "volume_size", "8"), ), @@ -470,6 +505,34 @@ data "aws_iam_policy_document" "assume_role" { `, notebookName, notebookName) } +func testAccAWSSagemakerNotebookInstanceConfigVolume(notebookName string) string { + return fmt.Sprintf(` +resource "aws_sagemaker_notebook_instance" "foo" { + name = "%s" + role_arn = aws_iam_role.foo.arn + instance_type = "ml.t2.medium" + volume_size = "5" +} + +resource "aws_iam_role" "foo" { + name = "%s" + path = "/" + assume_role_policy = data.aws_iam_policy_document.assume_role.json +} + +data "aws_iam_policy_document" "assume_role" { + statement { + actions = ["sts:AssumeRole"] + + principals { + type = "Service" + identifiers = ["sagemaker.amazonaws.com"] + } + } +} +`, notebookName, notebookName) +} + func testAccAWSSagemakerNotebookInstanceUpdateConfig(notebookName string) string { return fmt.Sprintf(` resource "aws_sagemaker_notebook_instance" "foo" {