Skip to content
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

Sagemaker notebook instance #7139

Merged
merged 23 commits into from
Jan 16, 2019
Merged

Sagemaker notebook instance #7139

merged 23 commits into from
Jan 16, 2019

Conversation

mbfrahry
Copy link
Member

@mbfrahry mbfrahry commented Jan 15, 2019

This PR starts the process to add the long requested sagemaker resources to the aws provider. Huge shoutout to @ddcprg in #2999 for getting the bulk of this done.

=== RUN   TestAccAWSSagemakerNotebookInstance_basic
=== PAUSE TestAccAWSSagemakerNotebookInstance_basic
=== RUN   TestAccAWSSagemakerNotebookInstance_update
=== PAUSE TestAccAWSSagemakerNotebookInstance_update
=== RUN   TestAccAWSSagemakerNotebookInstance_tags
=== PAUSE TestAccAWSSagemakerNotebookInstance_tags
=== CONT  TestAccAWSSagemakerNotebookInstance_basic
=== CONT  TestAccAWSSagemakerNotebookInstance_tags
=== CONT  TestAccAWSSagemakerNotebookInstance_update
--- PASS: TestAccAWSSagemakerNotebookInstance_tags (298.50s)
--- PASS: TestAccAWSSagemakerNotebookInstance_basic (431.74s)
--- PASS: TestAccAWSSagemakerNotebookInstance_update (483.99s)

@ghost ghost added size/XL Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. provider Pertains to the provider itself, rather than any interaction with AWS. service/sagemaker Issues and PRs that pertain to the sagemaker service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Jan 15, 2019
@mbfrahry mbfrahry requested a review from a team January 15, 2019 03:21
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mbfrahry 👋 A few little things then this should be good to go!

"name": {
Type: schema.TypeString,
Required: true,
Computed: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Computed: false is extraneous for attributes

func resourceAwsSagemakerNotebookInstanceRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).sagemakerconn

// TODO change this to describeNotebook Instance
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old comment? If not, please add GitHub issue URL

}
notebookInstance, err := conn.DescribeNotebookInstance(describeNotebookInput)
if err != nil {
if isAWSErr(err, "", "RecordNotFound") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does SageMaker not return an ErrorCode? Seems odd compared to other AWS services and likely AWS Go SDK bug worthy. Might be best to create a _disappears acceptance test and verify this. 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All other sagemaker resources return ResourceNotFound except for notebook instance. It's definitely odd.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the error that gets returned when you try and do something with a notebook instance that has been deleted ValidationException: RecordNotFound

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isAWSErr() does a strict check on the second parameter so isAWSErr(err, "ValidationException", "RecordNotFound") should do the trick then. 🎉

if err != nil {
if isAWSErr(err, "", "RecordNotFound") {
d.SetId("")
log.Printf("[LOG] Unable to find sageMaker notebook instance %q; removing from state file", d.Id())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: [LOG] is not an hclog log level

Suggested change
log.Printf("[LOG] Unable to find sageMaker notebook instance %q; removing from state file", d.Id())
log.Printf("[WARN] Unable to find SageMaker Notebook Instance (%s), removing from state", d.Id())

ResourceArn: notebookInstance.NotebookInstanceArn,
})
if err != nil {
log.Printf("[ERR] error reading tags: %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We should return this in the error message instead of just logging it

return fmt.Errorf("unable to find sagemaker notebook instance to delete %q: %s", d.Id(), err)
}
if *notebook.NotebookInstanceStatus != sagemaker.NotebookInstanceStatusFailed {
if err := stopSagemakerNotebookInstance(conn, d.Id()); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check to see if its already stopped and skip this if it is? It looks like stopSagemakerNotebookInstance might already check this so the DescribeNotebookInstance call above may be extraneous.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I guess stopSagemakerNotebookInstance returns different errors and whatnot. Adding the conditional for sagemaker.NotebookInstanceStatusStopped is probably best here. 👍

continue
}

resp, err := conn.ListNotebookInstances(&sagemaker.ListNotebookInstancesInput{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be using DescribeNotebookInstance to match the Read function and Exists test function? A name contains check seems more flakey than directly checking.


## Import

Models can be imported using the `name`, e.g.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍝

Suggested change
Models can be imported using the `name`, e.g.
SageMaker Notebook Instances can be imported using the `name`, e.g.

}
notebook, err := conn.DescribeNotebookInstance(describeNotebookInput)
if err != nil {
if sagemakerErr, ok := err.(awserr.Error); ok && sagemakerErr.Message() == "RecordNotFound" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be RecordNotFound or ResourceNotFound to match others?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RecordNotFound is the correct usage here


}

d.Set("security_groups", flattenStringList(notebookInstance.SecurityGroups))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add error checking here to match everything else 👍

Suggested change
d.Set("security_groups", flattenStringList(notebookInstance.SecurityGroups))
if err := d.Set("security_groups", flattenStringList(notebookInstance.SecurityGroups)); err != nil {
return fmt.Errorf("error setting security_groups for sagemaker notebook instance %q: %s", d.Id(), err)
}

@bflad bflad added the new-resource Introduces a new resource. label Jan 15, 2019
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 🎉 🎉 Thanks, @ddcprg and @mbfrahry!

--- PASS: TestAccAWSSagemakerNotebookInstance_disappears (236.38s)
--- PASS: TestAccAWSSagemakerNotebookInstance_basic (236.85s)
--- PASS: TestAccAWSSagemakerNotebookInstance_tags (403.87s)
--- PASS: TestAccAWSSagemakerNotebookInstance_update (570.45s)

@bflad bflad added this to the v1.56.0 milestone Jan 16, 2019
@bflad bflad merged commit af1244b into master Jan 16, 2019
bflad added a commit that referenced this pull request Jan 16, 2019
@bflad
Copy link
Contributor

bflad commented Jan 16, 2019

This has been released in version 1.56.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@mbfrahry mbfrahry deleted the sagemaker-notebook-instance branch January 17, 2019 03:56
@ddcprg
Copy link
Contributor

ddcprg commented Jan 18, 2019

Awesome @mbfrahry and @bflad !!! Massive thanks for taking over 🤘

@ddcprg
Copy link
Contributor

ddcprg commented Jan 22, 2019

Hi @mbfrahry and @bflad the aws_sagemaker_training_job resource was in this branch but was not merged together with the aws_sagemaker_notebook_instance resource. The PR #2955 also contains the resource implementation. Are you planning to include this soon?

@mbfrahry
Copy link
Member Author

Hey @ddcprg, apologies for not surfacing this earlier. I have the training job piece cleaned up in a branch but I'm not sure it's the best fit for a resource in Terraform. Resources in Terraform are thought of as immutable infrastructure to manage some application . Training jobs go against that by acting like an application. We fire it off, let it run to completion, and then go over the results of what happened. I believe another tool would be better suited for training jobs but I'm open to adding this if you or others feel strongly about it living inside of Terraform.

@ddcprg
Copy link
Contributor

ddcprg commented Jan 24, 2019

Thanks for the insight @mbfrahry that makes sense and if that's the philosophy of the project then I'm fine with keeping it out or leave the decision to the community. Cheers!

@ghost
Copy link

ghost commented Apr 1, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. new-resource Introduces a new resource. provider Pertains to the provider itself, rather than any interaction with AWS. service/sagemaker Issues and PRs that pertain to the sagemaker service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants