-
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
Sagemaker notebook instance #7139
Conversation
…endor-notebook-instance
…aform-providers/terraform-provider-aws into sagemaker-notebook-instance
…aform-providers/terraform-provider-aws into sagemaker-notebook-instance
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.
Hey @mbfrahry 👋 A few little things then this should be good to go!
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Computed: false, |
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.
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 |
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.
Old comment? If not, please add GitHub issue URL
} | ||
notebookInstance, err := conn.DescribeNotebookInstance(describeNotebookInput) | ||
if err != nil { | ||
if isAWSErr(err, "", "RecordNotFound") { |
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.
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. 👍
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.
All other sagemaker resources return ResourceNotFound except for notebook instance. It's definitely odd.
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.
This is the error that gets returned when you try and do something with a notebook instance that has been deleted ValidationException: RecordNotFound
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.
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()) |
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.
Nit: [LOG]
is not an hclog log level
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) |
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.
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 { |
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.
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.
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.
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{ |
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.
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. |
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.
🍝
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" { |
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.
Should this be RecordNotFound or ResourceNotFound to match others?
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.
RecordNotFound is the correct usage here
|
||
} | ||
|
||
d.Set("security_groups", flattenStringList(notebookInstance.SecurityGroups)) |
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.
Should add error checking here to match everything else 👍
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) | |
} |
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.
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. |
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. |
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! |
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! |
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.