-
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/vpc_dhcp_options: Update not found error message #4136
Conversation
aws/resource_aws_vpc_dhcp_options.go
Outdated
@@ -272,7 +272,7 @@ func resourceDHCPOptionsStateRefreshFunc(conn *ec2.EC2, id string) resource.Stat | |||
|
|||
resp, err := conn.DescribeDhcpOptions(DescribeDhcpOpts) | |||
if err != nil { | |||
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidDhcpOptionsID.NotFound" { | |||
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidDhcpOptionID.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.
Consider using isAWSErr
:
if isAWSErr(err, "InvalidDhcpOptionID.NotFound", "") {
or even extracting to own function
func isNoSuchDhcpOptionIDErr(err error) bool {
return isAWSErr(err, "InvalidDhcpOptionID.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.
Maybe check for both forms if you extract to a new function?
It seems both error messages have exactly the same description.
Capture both "InvalidDhcpOptionID.NotFound" and "InvalidDhcpOptionsID.NotFound" in all locations that refrenced either error.
@@ -212,7 +206,7 @@ func resourceAwsVpcDhcpOptionsDelete(d *schema.ResourceData, meta interface{}) e | |||
} | |||
|
|||
switch ec2err.Code() { | |||
case "InvalidDhcpOptionsID.NotFound": | |||
case "InvalidDhcpOptionsID.NotFound", "InvalidDhcpOptionID.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.
Option would be to adjust this to an if/if-else/else block and use the isAwsErr and the new function.
@ewbankkit adjusted and updated throughout as suggested. |
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.
Great find and fix! 🚀 Who would've thought there would be two duplicate error codes. 😉
4 tests passed (all tests)
=== RUN TestAccAWSDHCPOptions_deleteOptions
--- PASS: TestAccAWSDHCPOptions_deleteOptions (6.41s)
=== RUN TestAccAWSDHCPOptions_basic
--- PASS: TestAccAWSDHCPOptions_basic (7.48s)
=== RUN TestAccAWSDHCPOptions_importBasic
--- PASS: TestAccAWSDHCPOptions_importBasic (8.14s)
=== RUN TestAccAWSDHCPOptionsAssociation_basic
--- PASS: TestAccAWSDHCPOptionsAssociation_basic (9.55s)
This has been released in version 1.15.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! |
AWS uses the error code "InvalidDhcpOptionID.NotFound" and not the plural version when calling DescribeDhcpOptions. The check for the plural version in DeleteDhcpOptions is correct as AWS returns a plural version on this call.