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

New resource: aws_sagemaker_lifecycle_config #7585

Conversation

jckuester
Copy link
Contributor

This PR adds the resource aws_sagemaker_endpoint_configuration (including tests).

@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 Feb 15, 2019
@jckuester jckuester mentioned this pull request Feb 15, 2019
@bflad bflad added the new-resource Introduces a new resource. label Feb 16, 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.

Hi @jckuester 👋 Thanks for this submission here as well and initial review provided below. Please reach out with any questions or if you do not have time to implement the feedback. 👍

// (same for on_start)
if v, ok := d.GetOk("on_create"); ok {
hook := &sagemaker.NotebookInstanceLifecycleHook{Content: aws.String(v.(string))}
createOpts.SetOnCreate([]*sagemaker.NotebookInstanceLifecycleHook{hook})
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: As a style preference across the codebase for consistency, we typically prefer the equals syntax over the Set functions 👍

Suggested change
createOpts.SetOnCreate([]*sagemaker.NotebookInstanceLifecycleHook{hook})
createOpts.OnCreate = []*sagemaker.NotebookInstanceLifecycleHook{hook}


if v, ok := d.GetOk("on_start"); ok {
hook := &sagemaker.NotebookInstanceLifecycleHook{Content: aws.String(v.(string))}
createOpts.SetOnStart([]*sagemaker.NotebookInstanceLifecycleHook{hook})
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Same here: as a style preference across the codebase for consistency, we typically prefer the equals syntax over the Set functions 👍

Suggested change
createOpts.SetOnStart([]*sagemaker.NotebookInstanceLifecycleHook{hook})
createOpts.OnStart = []*sagemaker.NotebookInstanceLifecycleHook{hook}

Computed: true,
},

"name": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add validation for this field? e.g.

ValidateFunc: validation.StringLenBetween(1, 63),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"github.com/hashicorp/terraform/helper/validation"
)

func resourceAwsSagemakerLifeCycleConfiguration() *schema.Resource {
Copy link
Contributor

Choose a reason for hiding this comment

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

Its unfortunately verbose, but we should probably follow the API naming here for the resource functions and resource name to clarify this is specifically for managing Notebook Instance Lifecycle Configurations. This is in case the SageMaker API introduces other "Lifecycle Configurations".

aws_sagemaker_notebook_instance_lifecycle_configuration
Suggested change
func resourceAwsSagemakerLifeCycleConfiguration() *schema.Resource {
func resourceAwsSagemakerNotebookInstanceLifeCycleConfiguration() *schema.Resource {

return fmt.Errorf("error setting name for SageMaker notebook instance lifecycle configuration (%s): %s", d.Id(), err)
}

if len(lifecycleConfig.OnCreate) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

To prevent potential panics, this should perform a nil check

Suggested change
if len(lifecycleConfig.OnCreate) > 0 {
if len(lifecycleConfig.OnCreate) > 0 && lifecycleConfig.OnCreate[0] != nil {

}
log.Printf("[INFO] Deleting SageMaker notebook instance lifecycle configuration: %s", d.Id())

return resource.Retry(5*time.Minute, func() *resource.RetryError {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this resource.Retry() contains no return resource.RetryableError() conditions, the resource.Retry() logic should be removed.

testAccCheckAWSSagemakerLifecycleConfigurationExists(resourceName, &lifecycleConfig),

resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "on_create", base64Encode([]byte("echo foo"))),
Copy link
Contributor

Choose a reason for hiding this comment

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

The "basic" test configuration should omit any optional parameters and instead check for attribute zero-values or empty values, e.g.

resource.TestCheckNoResourceAttr(resourceName, "on_create"),
resource.TestCheckNoResourceAttr(resourceName, "on_start"),

Steps: []resource.TestStep{
{
Config: testAccSagemakerLifecycleConfigurationConfig_Basic(rName),
Check: resource.ComposeTestCheckFunc(
Copy link
Contributor

Choose a reason for hiding this comment

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

We should check the value of the arn attribute is populated correct in here, e.g.

testAccCheckResourceAttrRegionalARN(resourceName, "arn", "sagemaker", fmt.Sprintf("notebook-instance-lifecycle-config/%s", rName)),


if err != nil {
if isAWSErr(err, "ValidationException", "") {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

CheckDestroy functions should use continue instead of return nil to allow checking multiple declarations of the resource.

return fmt.Errorf("SageMaker notebook instance lifecycle configuration %s still exists", rs.Primary.ID)
}

return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here although the line can just be removed since it is the end of the for loop logic.

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Mar 26, 2019
@jckuester jckuester force-pushed the feature/resource_aws_sagemaker_lifecycle_config branch from 9f35135 to 3e94716 Compare April 1, 2019 09:14
@ghost ghost added size/XXL Managed by automation to categorize the size of a PR. and removed size/XL Managed by automation to categorize the size of a PR. labels Apr 1, 2019
@jckuester jckuester force-pushed the feature/resource_aws_sagemaker_lifecycle_config branch from 3e94716 to fb7d50d Compare April 1, 2019 09:37
@jckuester
Copy link
Contributor Author

@bflad I addressed your feedback (see last commit).

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Apr 1, 2019
@bflad bflad added this to the v2.5.0 milestone Apr 5, 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.

This looks great as well. Thanks @jckuester! 🚀

--- PASS: TestAccAWSSagemakerNotebookInstanceLifecycleConfiguration_Basic (10.36s)
--- PASS: TestAccAWSSagemakerNotebookInstanceLifecycleConfiguration_Update (15.74s)

@bflad bflad merged commit fb7d50d into hashicorp:master Apr 5, 2019
bflad added a commit that referenced this pull request Apr 5, 2019
@bflad
Copy link
Contributor

bflad commented Apr 5, 2019

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

@jckuester jckuester deleted the feature/resource_aws_sagemaker_lifecycle_config branch August 6, 2019 20:15
@ghost
Copy link

ghost commented Nov 2, 2019

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 Nov 2, 2019
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/XXL 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.

2 participants