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

Resource - Neptune: aws_neptune_parameter_group #4724

Merged
merged 15 commits into from
Jun 13, 2018
Merged

Conversation

dav009
Copy link
Contributor

@dav009 dav009 commented Jun 1, 2018

Reference: #4713

Changes proposed in this pull request:

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccAWSNeptuneParameterGroup_basic'
=== RUN   TestAccAWSNeptuneParameterGroup_basic
--- PASS: TestAccAWSNeptuneParameterGroup_basic

$ make testacc TESTARGS='-run=TestAccAWSNeptuneParameterGroup_removeParam'
=== RUN   TestAccAWSNeptuneParameterGroup_removeParam
--- PASS: TestAccAWSNeptuneParameterGroup_removeParam

$ make testacc TESTARGS='-run=TestAccAWSNeptuneParameterGroup_only'
=== RUN   TestAccAWSNeptuneParameterGroup_only
--- PASS: TestAccAWSNeptuneParameterGroup_only

@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Jun 1, 2018
@dav009 dav009 mentioned this pull request Jun 1, 2018
@bflad bflad added new-resource Introduces a new resource. service/neptune Issues and PRs that pertain to the neptune service. labels Jun 1, 2018
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 @dav009 👋 Thanks for submitting this! Its looking pretty good so far. Please see the below for some feedback then we can get this in. Let us know if you have any questions or do not have time to implement the feedback.

State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nitpick: As of Go 1.7, the &schema.Schema declarations are optional due to the type declaration of map[string]*schema.Schema and we prefer to remove them.


describeResp, err := conn.DescribeDBParameterGroups(&describeOpts)
if err != nil {
return err
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 for an error here to indicate that the parameter group has been removed outside of Terraform and remove it from the Terraform state so it can successfully be recreated:

if isAWSErr(err, neptune.ErrCodeDBParameterGroupNotFoundFault, "") {
  log.Printf("[WARN] Neptune Parameter Group (%s) not found, removing from state", d.Id())
  d.SetId("")
  return nil
}
return err

return err
}

if len(describeResp.DBParameterGroups) != 1 ||
Copy link
Contributor

Choose a reason for hiding this comment

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

While we are trying to prevent errors/panics here we should check describeResp == nil as well in the (unlikely) scenario that it comes back empty from the API without an error.

Source: aws.String("user"),
}

describeParametersResp, err := conn.DescribeDBParameters(&describeParametersOpts)
Copy link
Contributor

Choose a reason for hiding this comment

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

This API call is not currently handling Marker for pagination, which means it may not receive all results in large or separated API responses. Instead, we should probably use the available SDK pagination function: DescribeDBParametersPages

return err
}

d.Set("parameter", flattenNeptuneParameters(describeParametersResp.Parameters))
Copy link
Contributor

Choose a reason for hiding this comment

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

When setting the value of a non-scalar attribute into the Terraform state, we should prefer to error check it:

if err := d.Set("parameter", flattenNeptuneParameters(parameters)); err != nil {
  return fmt.Errorf("error setting parameter: %s", err)
}

Type: schema.TypeString,
Required: true,
},
"apply_method": &schema.Schema{
Copy link
Contributor

Choose a reason for hiding this comment

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

The SDK provides two constants we can use for value validation and to ensure the value is correctly lowercase:

ValidateFunc: validation.StringInSlice([]string{
  neptune.ApplyMethodImmediate,
  neptune.ApplyMethodPendingReboot,
}, false),


// We can only modify 20 parameters at a time, so walk them until
// we've got them all.
maxParams := 20
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nitpick: We should probably set this as a top level constant

"aws_neptune_parameter_group.bar", "family", "neptune1"),
resource.TestCheckResourceAttr(
"aws_neptune_parameter_group.bar", "description", "Managed by Terraform"),
resource.TestCheckResourceAttr(
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nitpick: when testing nested attributes like TypeList and TypeSet, we should check the associated value count as well: resource.TestCheckResourceAttr("aws_neptune_parameter_group.bar", "parameter.#", "1")

We should apply this to any of the other tests below where we also expect a certain number of parameters (especially the removal test).

PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSNeptuneParameterGroupDestroy,
Steps: []resource.TestStep{
Copy link
Contributor

Choose a reason for hiding this comment

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

To test importing the resource, we should add the following TestStep at the end:

{
  ResourceName:      "aws_neptune_parameter_group.bar",
  ImportState:       true,
  ImportStateVerify: true,
},

aws/structure.go Outdated
for _, i := range list {
if i.ParameterValue != nil {
result = append(result, map[string]interface{}{
"name": strings.ToLower(*i.ParameterName),
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 panic scenarios, we should use the SDK function here and below to dereference the response objects, rather than *: e.g. aws.StringValue(i.ParameterName)

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Jun 3, 2018
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Jun 8, 2018
@dav009
Copy link
Contributor Author

dav009 commented Jun 8, 2018

@bflad

  • addressed your comments
  • added docs
    🙇

@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Jun 8, 2018
@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label Jun 13, 2018
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 so much for your work here @dav009! I found a few other things while reviewing and testing, which I made comments below but will fix in a commit after yours. Excited to see the beginning of Neptune support take off! 🚀

It was previously passing acceptance testing, but after feedback updates:

make testacc TEST=./aws TESTARGS='-run=TestAccAWSNeptuneParameterGroup'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSNeptuneParameterGroup -timeout 120m
=== RUN   TestAccAWSNeptuneParameterGroup_basic
--- PASS: TestAccAWSNeptuneParameterGroup_basic (14.14s)
=== RUN   TestAccAWSNeptuneParameterGroup_Description
--- PASS: TestAccAWSNeptuneParameterGroup_Description (14.47s)
=== RUN   TestAccAWSNeptuneParameterGroup_Parameter
--- PASS: TestAccAWSNeptuneParameterGroup_Parameter (25.46s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	54.107s

"apply_method": {
Type: schema.TypeString,
Optional: true,
Default: "immediate",
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be safer to default to pending-reboot as that is applicable to both static and dynamic parameters.

Type: schema.TypeString,
Required: true,
},
"apply_method": {
Copy link
Contributor

Choose a reason for hiding this comment

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

This argument was not documented originally and will be added post merge. Also adding validation:

ValidateFunc: validation.StringInSlice([]string{
	neptune.ApplyMethodImmediate,
	neptune.ApplyMethodPendingReboot,
}, false),

// us what we used for apply_method previously, so
// by squashing state to an empty string we avoid
// needing to do an update for every future run.
StateFunc: func(interface{}) string { return "" },
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure where this StateFunc and the comment came from, but the current Neptune API does properly return ApplyMethod so we can set it in the Terraform state without modification.

},
},
},
Set: resourceAwsNeptuneParameterHash,
Copy link
Contributor

Choose a reason for hiding this comment

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

It turns out that this custom Set function was extraneous as we want to have apply_method computed as a difference if it changed.

for _, i := range list {
if i.ParameterValue != nil {
result = append(result, map[string]interface{}{
"name": strings.ToLower(aws.StringValue(i.ParameterName)),
Copy link
Contributor

Choose a reason for hiding this comment

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

The strings.ToLower() here seems extraneous. We can always add it back if for some reason its necessary.

result = append(result, map[string]interface{}{
"name": strings.ToLower(aws.StringValue(i.ParameterName)),
"value": aws.StringValue(i.ParameterValue),
"apply_method": strings.ToLower(aws.StringValue(i.ParameterName)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Two issues:

  • Its reading ParameterName and not ApplyMethod
  • The strings.ToLower() seems extraneous.

* `family` - (Required) The family of the Neptune parameter group.
* `description` - (Optional) The description of the Neptune parameter group. Defaults to "Managed by Terraform".
* `parameter` - (Optional) A list of Neptune parameters to apply.
* `tags` - (Optional) A mapping of tags to assign to the resource.
Copy link
Contributor

Choose a reason for hiding this comment

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

The tags attribute is not currently implemented and will be removed from the documentation.


The following attributes are exported:

* `id` - The dbNeptune parameter group name.
Copy link
Contributor

Choose a reason for hiding this comment

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

😎 Small typo dbNeptune

@bflad bflad merged commit bead75e into hashicorp:master Jun 13, 2018
bflad added a commit that referenced this pull request Jun 13, 2018
…nsure acceptance testing is per attribute

make testacc TEST=./aws TESTARGS='-run=TestAccAWSNeptuneParameterGroup'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSNeptuneParameterGroup -timeout 120m
=== RUN   TestAccAWSNeptuneParameterGroup_basic
--- PASS: TestAccAWSNeptuneParameterGroup_basic (14.14s)
=== RUN   TestAccAWSNeptuneParameterGroup_Description
--- PASS: TestAccAWSNeptuneParameterGroup_Description (14.47s)
=== RUN   TestAccAWSNeptuneParameterGroup_Parameter
--- PASS: TestAccAWSNeptuneParameterGroup_Parameter (25.46s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	54.107s
@bflad bflad added this to the v1.23.0 milestone Jun 13, 2018
bflad added a commit that referenced this pull request Jun 13, 2018
@bflad
Copy link
Contributor

bflad commented Jun 14, 2018

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

@ghost
Copy link

ghost commented Apr 5, 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 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-resource Introduces a new resource. service/neptune Issues and PRs that pertain to the neptune service. size/XL Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants