-
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
Resource - Neptune: aws_neptune_parameter_group #4724
Conversation
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.
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{ |
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.
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 |
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.
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 || |
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.
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) |
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 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)) |
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.
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{ |
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.
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 |
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.
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( |
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.
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{ |
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.
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), |
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.
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)
|
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.
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", |
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 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": { |
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 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 "" }, |
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.
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, |
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.
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)), |
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.
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)), |
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.
Two issues:
- Its reading
ParameterName
and notApplyMethod
- 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. |
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.
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. |
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.
😎 Small typo dbNeptune
…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
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. |
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! |
Reference: #4713
Changes proposed in this pull request:
aws_neptune_parameter_group
as a first step to address Support Neptune #4713Output from acceptance testing: