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_neptune_cluster_parameter_group #4860

Merged
merged 6 commits into from
Jun 18, 2018

Conversation

saravanan30erd
Copy link
Contributor

@saravanan30erd saravanan30erd commented Jun 17, 2018

Reference #4713

Changes proposed in this pull request:

  • Change 1
    added new resource neptune cluster parameter group
$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSNeptuneClusterParameterGroup'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -run=TestAccAWSNeptuneClusterParameterGroup -timeout 120m
=== RUN   TestAccAWSNeptuneClusterParameterGroup_basic
--- PASS: TestAccAWSNeptuneClusterParameterGroup_basic (50.01s)
=== RUN   TestAccAWSNeptuneClusterParameterGroup_namePrefix
--- PASS: TestAccAWSNeptuneClusterParameterGroup_namePrefix (44.31s)
=== RUN   TestAccAWSNeptuneClusterParameterGroup_generatedName
--- PASS: TestAccAWSNeptuneClusterParameterGroup_generatedName (46.43s)
=== RUN   TestAccAWSNeptuneClusterParameterGroup_withoutParameter
--- PASS: TestAccAWSNeptuneClusterParameterGroup_withoutParameter (46.04s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	186.824s
...

@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Jun 17, 2018
@bflad bflad added new-resource Introduces a new resource. service/neptune Issues and PRs that pertain to the neptune service. labels Jun 18, 2018
_, errors := validateNeptuneParamGroupName(tc.Value, "aws_neptune_cluster_parameter_group_name")

if len(errors) != tc.ErrCount {
t.Fatalf("Expected the Neptune Parameter Group Name to trigger a validation error")
Copy link
Contributor

Choose a reason for hiding this comment

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

One of the test cases is generating unit test failures:

--- FAIL: TestValidateNeptuneParamGroupNamePrefix (0.00s)
	validators_test.go:2733: Expected the Neptune Parameter Group Name to trigger a validation error

Can you please include tc.Value in the error messaging here and below, then fix the test case? Thanks!

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 for submitting this @saravanan30erd! I left some feedback beyond just the unit testing piece. It will probably be good to go after. Please let us know if you have any questions or do not have time to implement this.

Check: resource.ComposeTestCheckFunc(
testAccCheckAWSNeptuneClusterParameterGroupExists("aws_neptune_cluster_parameter_group.bar", &v),
testAccCheckAWSNeptuneClusterParameterGroupAttributes(&v, parameterGroupName),
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.

We should check the arn attribute value as well:

resource.TestMatchResourceAttr("aws_neptune_cluster_parameter_group.bar", "arn", regexp.MustCompile(fmt.Sprintf("^arn:[^:]+:neptune:[^:]+:\\d{12}:cluster-pg:%s", parameterGroupName)))

}
}

arn := arn.ARN{
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 use the value of the ARN from the Terraform state (coming from the API) rather than manually generating it:

arn := d.Get("arn").(string)

Since we're calling update after create, we'll need to d.Set("arn", ...) in the create function as well as read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, thats what I am looking for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, done.


describeResp, err := conn.DescribeDBClusterParameterGroups(&describeOpts)
if err != nil {
if isAWSErr(err, neptune.ErrCodeDBParameterGroupNotFoundFault, "") {
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 a separate constant for cluster parameter groups: ErrCodeDBClusterParameterGroupNotFoundFault


if len(describeResp.DBClusterParameterGroups) != 1 ||
aws.StringValue(describeResp.DBClusterParameterGroups[0].DBClusterParameterGroupName) != d.Id() {
return fmt.Errorf("Unable to find Cluster Parameter Group: %#v", describeResp.DBClusterParameterGroups)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just like the regular parameter groups we should presume the API will return the correct result (terraform's plan would look very wrong otherwise) -- checking for zero length to recreate the resource instead of returning an error:

if len(describeResp.DbClusterParameterGroups) == 0 {
  log.Printf("[WARN] Neptune Cluster Parameter Group (%s) not found, removing from state", d.Id())
  d.SetId("")
  return nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, I understood. But anyway we don't need to check for zero length right? since it should be covered by ErrCodeDBClusterParameterGroupNotFoundFault.

Copy link
Contributor

Choose a reason for hiding this comment

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

We've seen cases where some service APIs will respond with no errors and also an empty result set. In any case, its best to include the handling to prevent Terraform from crashing with the Go panic of index not in range.

log.Printf("[DEBUG] Deleting Neptune Cluster Parameter Group: %s", d.Id())
_, err := conn.DeleteDBClusterParameterGroup(&input)
if err != nil {
if isAWSErr(err, neptune.ErrCodeDBParameterGroupNotFoundFault, "") {
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 a separate constant for cluster parameter groups: ErrCodeDBClusterParameterGroupNotFoundFault

}

if err != nil {
if isAWSErr(err, neptune.ErrCodeDBParameterGroupNotFoundFault, "") {
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 a separate constant for cluster parameter groups: ErrCodeDBClusterParameterGroupNotFoundFault

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bflad Looks like ErrCodeDBClusterParameterGroupNotFoundFault only available for createdbcluster and modifydbcluster and ErrCodeDBParameterGroupNotFoundFault is the one used for other functions.
https://docs.aws.amazon.com/sdk-for-go/api/service/neptune/#Neptune.DeleteDBClusterParameterGroup

Copy link
Contributor

Choose a reason for hiding this comment

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

🙁 this is either an error in the AWS documentation or an oversight. I will reach out to AWS support for clarification.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry this was a bad assumption on my part. This behavior is frustrating:

$ aws neptune describe-db-cluster-parameter-groups --db-cluster-parameter-group-name does-not-exist

An error occurred (DBParameterGroupNotFound) when calling the DescribeDBClusterParameterGroups operation: DBClusterParameterGroup not found: does-not-exist

$ aws neptune delete-db-cluster-parameter-group --db-cluster-parameter-group-name does-not-exist

An error occurred (DBParameterGroupNotFound) when calling the DeleteDBClusterParameterGroup operation: DBClusterParameterGroup not found: does-not-exist

$ aws neptune modify-db-cluster-parameter-group --db-cluster-parameter-group-name does-not-exist --parameters 'ParameterName=test,ParameterValue=""'

An error occurred (DBParameterGroupNotFound) when calling the ModifyDBClusterParameterGroup operation: Parameter group does not exist

I guess we should stick with the non-Cluster constant and add a comment to each instance about why its not using the Cluster constant. My apologies.

Copy link
Contributor Author

@saravanan30erd saravanan30erd Jun 18, 2018

Choose a reason for hiding this comment

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

yes, acceptance tests were failed when I was tryingErrCodeDBClusterParameterGroupNotFoundFault .

---
layout: "aws"
page_title: "AWS: aws_neptune_cluster_parameter_group"
sidebar_current: "docs-aws-resource-aws-neptune-cluster-parameter-group"
Copy link
Contributor

Choose a reason for hiding this comment

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

Documentation page is missing a sidebar link in website/aws.erb

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, also I found duplicate entry for neptune parameter group in this file and removed it.

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Jun 18, 2018
@saravanan30erd saravanan30erd changed the title Neptune clus param grp New Resource: aws_neptune_cluster_parameter_group Jun 18, 2018
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Jun 18, 2018
@saravanan30erd
Copy link
Contributor Author

@bflad thanks for feedback, I done all the changes 👍

@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label Jun 18, 2018
@bflad bflad added this to the v1.24.0 milestone Jun 18, 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.

This should be pretty good to go, thanks @saravanan30erd! I'll add an import test case post-merge and ensure that parameters are updating correctly via acceptance testing. 🚀

4 tests passed (all tests)
--- PASS: TestAccAWSNeptuneClusterParameterGroup_namePrefix (6.58s)
=== RUN   TestAccAWSNeptuneClusterParameterGroup_generatedName
--- PASS: TestAccAWSNeptuneClusterParameterGroup_generatedName (6.65s)
=== RUN   TestAccAWSNeptuneClusterParameterGroup_withoutParameter
--- PASS: TestAccAWSNeptuneClusterParameterGroup_withoutParameter (6.75s)
=== RUN   TestAccAWSNeptuneClusterParameterGroup_basic
--- PASS: TestAccAWSNeptuneClusterParameterGroup_basic (6.85s)

@bflad bflad merged commit 2764126 into hashicorp:master Jun 18, 2018
bflad added a commit that referenced this pull request Jun 18, 2018
darrenhaken pushed a commit to darrenhaken/terraform-provider-aws that referenced this pull request Jun 20, 2018
@bflad
Copy link
Contributor

bflad commented Jun 25, 2018

This has been released in version 1.24.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