-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Conversation
$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSNeptuneSubnetGroup' |
2c7bd59
to
bdf88ab
Compare
This is now ready for rebase since the parameter group resource was merged yesterday 👍 |
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 @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) |
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: comment can be removed 😄
} | ||
return !lastPage | ||
}); err != nil { | ||
if neptuneerr, ok := err.(awserr.Error); ok && neptuneerr.Code() == "DBSubnetGroupNotFoundFault" { |
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.
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) |
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 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 |
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.
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) |
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.
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 { |
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 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) { |
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.
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.
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.
removed this acceptance test.
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.
Unit testing for this validation already covered in validators_test.go
. still we need to add unit testing here?
aws/tagsNeptune.go
Outdated
// First, we're creating everything we have | ||
create := make(map[string]interface{}) | ||
for _, t := range newTags { | ||
create[*t.Key] = *t.Value |
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 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.
aws/validators.go
Outdated
errors = append(errors, fmt.Errorf( | ||
"%q cannot be longer than 255 characters", k)) | ||
} | ||
if regexp.MustCompile(`(?i)^default$`).MatchString(value) { |
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.
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" {
aws/validators.go
Outdated
errors = append(errors, fmt.Errorf( | ||
"only lowercase alphanumeric characters, hyphens, underscores, periods, and spaces allowed in %q", k)) | ||
} | ||
if len(value) > 229 { |
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 opt to include how we came to this value, e.g.
prefixMaxLength := 255 - resource.UniqueIDSuffixLength
@bflad done all the changes. |
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 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{ |
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.
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,
},
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. |
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