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

issue #4713 New resource aws_neptune_subnet_group #4782

Merged
merged 7 commits into from
Jun 15, 2018

Conversation

saravanan30erd
Copy link
Contributor

@saravanan30erd saravanan30erd commented Jun 7, 2018

Reference: #4713

@ghost ghost added the size/XXL Managed by automation to categorize the size of a PR. label Jun 7, 2018
@saravanan30erd
Copy link
Contributor Author

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSNeptuneSubnetGroup'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -run=TestAccAWSNeptuneSubnetGroup -timeout 120m
=== RUN TestAccAWSNeptuneSubnetGroup_basic
--- PASS: TestAccAWSNeptuneSubnetGroup_basic (94.48s)
=== RUN TestAccAWSNeptuneSubnetGroup_namePrefix
--- PASS: TestAccAWSNeptuneSubnetGroup_namePrefix (95.88s)
=== RUN TestAccAWSNeptuneSubnetGroup_generatedName
--- PASS: TestAccAWSNeptuneSubnetGroup_generatedName (92.99s)
=== RUN TestAccAWSNeptuneSubnetGroup_withUndocumentedCharacters
--- PASS: TestAccAWSNeptuneSubnetGroup_withUndocumentedCharacters (104.20s)
=== RUN TestAccAWSNeptuneSubnetGroup_updateDescription
--- PASS: TestAccAWSNeptuneSubnetGroup_updateDescription (165.62s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 553.208s

@ghost ghost added the size/XXL Managed by automation to categorize the size of a PR. label Jun 9, 2018
@bflad bflad added new-resource Introduces a new resource. service/neptune Issues and PRs that pertain to the neptune service. labels Jun 12, 2018
@bflad
Copy link
Contributor

bflad commented Jun 14, 2018

This is now ready for rebase since the parameter group resource was merged yesterday 👍

@ghost ghost added the size/XXL Managed by automation to categorize the size of a PR. label Jun 14, 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 @saravanan30erd -- thanks for submitting this! I left some initial feedback below, a lot of which probably comes from copying the RDS subnet group resource and testing. Please let us know if you have any questions or do not have time to implement the feedback.

}

var subnetGroups []*neptune.DBSubnetGroup
//describeResp, err := conn.DescribeDBSubnetGroups(&describeOpts)
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: comment can be removed 😄

}
return !lastPage
}); err != nil {
if neptuneerr, ok := err.(awserr.Error); ok && neptuneerr.Code() == "DBSubnetGroupNotFoundFault" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: We can use the helper function and SDK provided constant here -- we should also provide a log message when removing a resource from the state, e.g.

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

}

if len(subnetGroups) == 0 {
return fmt.Errorf("Unable to find Neptune Subnet Group: %#v", subnetGroups)
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 provide the log message and remove from state, similar to the above error handling, rather than returning an error here.

return fmt.Errorf("Unable to find Neptune Subnet Group: %#v", subnetGroups)
}

var subnetGroup *neptune.DBSubnetGroup
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that we force lowercase naming via the validation functions, it should be safe to assume here that we can directly access the first element of the slice instead of this extra logic.

subnetGroup := subnetGroups[0]

for _, s := range subnetGroup.Subnets {
subnets = append(subnets, aws.StringValue(s.SubnetIdentifier))
}
d.Set("subnet_ids", subnets)
Copy link
Contributor

Choose a reason for hiding this comment

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

For TypeSet attributes, we should perform error checking, e.g.

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

In this case I believe you'll find that setting this attribute needs to be occur with schema.NewSet(), e.g. something like

if err := d.Set("subnet_ids", schema.NewSet(schema.HashString, subnets)); err != nil {
  return fmt.Errorf("error setting subnet_ids: %s", err)
}

func TestAccAWSNeptuneSubnetGroup_basic(t *testing.T) {
var v neptune.DBSubnetGroup

testCheck := func(*terraform.State) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function seems extraneous


// Regression test for https://github.com/hashicorp/terraform/issues/2603 and
// https://github.com/hashicorp/terraform/issues/2664
func TestAccAWSNeptuneSubnetGroup_withUndocumentedCharacters(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Acceptable characters are in the CreateDBSubnetGroup API documentation:

Constraints: Must contain no more than 255 letters, numbers, periods, underscores, spaces, or hyphens. Must not be default.

This validation should be performed in unit testing and not acceptance testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed this acceptance test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unit testing for this validation already covered in validators_test.go. still we need to add unit testing here?

// First, we're creating everything we have
create := make(map[string]interface{})
for _, t := range newTags {
create[*t.Key] = *t.Value
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 in the unlikely cases that the key or value is nil we may want to consider using aws.StringValue() instead of direct * dereferences across this file.

errors = append(errors, fmt.Errorf(
"%q cannot be longer than 255 characters", k))
}
if regexp.MustCompile(`(?i)^default$`).MatchString(value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we have already validated that the value must be lowercase previously, we should opt to directly check the string instead, e.g.

if value == "default" {

errors = append(errors, fmt.Errorf(
"only lowercase alphanumeric characters, hyphens, underscores, periods, and spaces allowed in %q", k))
}
if len(value) > 229 {
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 opt to include how we came to this value, e.g.

prefixMaxLength := 255 - resource.UniqueIDSuffixLength

@ghost ghost added size/XL Managed by automation to categorize the size of a PR. and removed size/XXL Managed by automation to categorize the size of a PR. labels Jun 14, 2018
@saravanan30erd
Copy link
Contributor Author

@bflad done all the changes.

@bflad bflad added this to the v1.24.0 milestone Jun 15, 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 for the updates @saravanan30erd! Let's get this in. 🚀

(I'll add the import tests post-merge)

4 tests passed (all tests)
=== RUN   TestAccAWSNeptuneSubnetGroup_basic
--- PASS: TestAccAWSNeptuneSubnetGroup_basic (9.29s)
=== RUN   TestAccAWSNeptuneSubnetGroup_namePrefix
--- PASS: TestAccAWSNeptuneSubnetGroup_namePrefix (9.38s)
=== RUN   TestAccAWSNeptuneSubnetGroup_generatedName
--- PASS: TestAccAWSNeptuneSubnetGroup_generatedName (9.66s)
=== RUN   TestAccAWSNeptuneSubnetGroup_updateDescription
--- PASS: TestAccAWSNeptuneSubnetGroup_updateDescription (16.64s)

Read: resourceAwsNeptuneSubnetGroupRead,
Update: resourceAwsNeptuneSubnetGroupUpdate,
Delete: resourceAwsNeptuneSubnetGroupDelete,
Importer: &schema.ResourceImporter{
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I missed this before, looks like we're missing import test cases, e.g.

{
  ResourceName:      "aws_neptune_subnet_group.test",
  ImportState:       true,
  ImportStateVerify: true,
},

@bflad bflad merged commit 2f1f9c6 into hashicorp:master Jun 15, 2018
bflad added a commit that referenced this pull request Jun 15, 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