-
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
Add check destroy for aws ebs snapshot copy resource & Fix error handling #9106
Add check destroy for aws ebs snapshot copy resource & Fix error handling #9106
Conversation
Add acctest for when resource disappears
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 these fixes, @kterada0509 👍 The EC2 error code fix here looks good according to https://docs.aws.amazon.com/AWSEC2/latest/APIReference/errors-overview.html
Left one blocking feedback item concerning the usage of return nil
in the new CheckDestroy
function and some preferred simplifications to use isAWSErr()
instead of awserr
directly. Please let us know if you have any questions or do not have time to implement the feedback items.
@@ -116,7 +116,7 @@ func resourceAwsEbsSnapshotCopyRead(d *schema.ResourceData, meta interface{}) er | |||
SnapshotIds: []*string{aws.String(d.Id())}, | |||
} | |||
res, err := conn.DescribeSnapshots(req) | |||
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidSnapshotID.NotFound" { | |||
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidSnapshot.NotFound" { |
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.
These can be simplified using isAWSErr(err, CODE, MESSAGE)
in the future, e.g.
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidSnapshot.NotFound" { | |
if isAWSErr(err, "InvalidSnapshot.NotFound", "") { |
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.
fixed.
@@ -153,10 +153,14 @@ func resourceAwsEbsSnapshotCopyDelete(d *schema.ResourceData, meta interface{}) | |||
} | |||
|
|||
ebsErr, ok := err.(awserr.Error) | |||
if ebsErr.Code() == "SnapshotInUse" { | |||
if ok && ebsErr.Code() == "SnapshotInUse" { |
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.
Leaving as non-blocking feedback for next time.
if ok && ebsErr.Code() == "SnapshotInUse" { | |
if isAWSErr(err, "SnapshotInUse", "") { |
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.
fixed.
return resource.RetryableError(fmt.Errorf("EBS SnapshotInUse - trying again while it detaches")) | ||
} | ||
|
||
if ok && ebsErr.Code() == "InvalidSnapshot.NotFound" { |
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.
if ok && ebsErr.Code() == "InvalidSnapshot.NotFound" { | |
if isAWSErr(err, "InvalidSnapshot.NotFound", "") { |
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.
fixed.
SnapshotIds: []*string{aws.String(rs.Primary.ID)}, | ||
}) | ||
|
||
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidSnapshot.NotFound" { |
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.
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidSnapshot.NotFound" { | |
if isAWSErr(err, "InvalidSnapshot.NotFound", "") { |
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.
fixed.
}) | ||
|
||
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidSnapshot.NotFound" { | ||
return nil |
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.
CheckDestroy
should not use return nil
in the for
loop, to ensure all resources are properly checked. 👍
return nil | |
continue |
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.
fixed.
Re-run acctest.
|
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.
Looks great, thanks, @kterada0509! 🚀
--- PASS: TestAccAWSEbsSnapshotCopy_basic (49.04s)
--- PASS: TestAccAWSEbsSnapshotCopy_disappears (64.13s)
--- PASS: TestAccAWSEbsSnapshotCopy_withDescription (64.40s)
--- PASS: TestAccAWSEbsSnapshotCopy_withKms (82.87s)
--- PASS: TestAccAWSEbsSnapshotCopy_withRegions (99.52s)
This has been released in version 2.17.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks! |
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! |
Community Note
References #8958
Release note for CHANGELOG:
Output from acceptance testing: