-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature(sagemaker notebook): Add DirectInternetAccess support #8618
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -324,6 +324,57 @@ func testAccCheckAWSSagemakerNotebookInstanceName(notebook *sagemaker.DescribeNo | |
} | ||
} | ||
|
||
func TestAccAWSSagemakerNotebookInstance_direct_internet_access(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: testAccAWSSagemakerNotebookInstanceConfigDirectInternetAccess(notebookName, "Disabled"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSSagemakerNotebookInstanceExists(resourceName, ¬ebook), | ||
testAccCheckAWSSagemakerNotebookInstanceName(¬ebook, notebookName), | ||
testAccCheckAWSSagemakerNotebookDirectInternetAccess(¬ebook, "Disabled"), | ||
|
||
resource.TestCheckResourceAttr( | ||
"aws_sagemaker_notebook_instance.foo", "name", notebookName), | ||
), | ||
}, | ||
{ | ||
Config: testAccAWSSagemakerNotebookInstanceConfigDirectInternetAccess(notebookName, "Enabled"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSSagemakerNotebookInstanceExists(resourceName, ¬ebook), | ||
testAccCheckAWSSagemakerNotebookInstanceName(¬ebook, notebookName), | ||
testAccCheckAWSSagemakerNotebookDirectInternetAccess(¬ebook, "Enabled"), | ||
|
||
resource.TestCheckResourceAttr( | ||
"aws_sagemaker_notebook_instance.foo", "name", notebookName), | ||
), | ||
}, | ||
{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAWSSagemakerNotebookDirectInternetAccess(notebook *sagemaker.DescribeNotebookInstanceOutput, expected string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
directInternetAccess := notebook.DirectInternetAccess | ||
if *directInternetAccess != expected { | ||
return fmt.Errorf("direct_internet_access setting is incorrect: %s", *notebook.DirectInternetAccess) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccCheckAWSSagemakerNotebookInstanceTags(notebook *sagemaker.DescribeNotebookInstanceOutput, key string, value string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).sagemakerconn | ||
|
@@ -501,3 +552,48 @@ data "aws_iam_policy_document" "assume_role" { | |
} | ||
`, notebookName, notebookName) | ||
} | ||
|
||
func testAccAWSSagemakerNotebookInstanceConfigDirectInternetAccess(notebookName string, directInternetAccess string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_sagemaker_notebook_instance" "foo" { | ||
name = %[1]q | ||
role_arn = "${aws_iam_role.foo.arn}" | ||
instance_type = "ml.t2.medium" | ||
subnet_id = "${aws_subnet.sagemaker.id}" | ||
direct_internet_access = %[2]q | ||
} | ||
|
||
resource "aws_iam_role" "foo" { | ||
name = %[1]q | ||
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" ] | ||
} | ||
} | ||
} | ||
|
||
resource "aws_vpc" "test" { | ||
cidr_block = "10.0.10.0/24" | ||
|
||
tags = { | ||
Name = "tf-acc-test-sagemaker-notebook-instance-direct-internet-access" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "sagemaker" { | ||
vpc_id = "${aws_vpc.test.id}" | ||
cidr_block = "10.0.0.0/27" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test configuration is currently failing the new testing:
After updating this argument, the testing was still failing with:
Adding an |
||
|
||
tags = { | ||
Name = "tf-acc-test-sagemaker-notebook-instance-direct-internet-access" | ||
} | ||
} | ||
`, notebookName, directInternetAccess) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the API defaults this attribute to
Enabled
, this schema also needsDefault: sagemaker.DirectInternetAccessEnabled
to prevent Terraform from recreating resources which do not have it defined: