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

resource/vpc_dhcp_options: Update not found error message #4136

Merged
merged 2 commits into from
Apr 12, 2018

Conversation

gseyetik
Copy link
Contributor

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.

2018-04-06T13:01:46.772Z [DEBUG] plugin.terraform-provider-aws_v1.5.2: <Response><Errors><Error><Code>InvalidDhcpOptionID.NotFound</Code><Message>The dhcpOption ID 'id-removed' does not exist</Message></Error></Errors><RequestID>req-id-removed</RequestID></Response>                 
2018-04-06T13:01:46.772Z [DEBUG] plugin.terraform-provider-aws_v1.5.2: 2018/04/06 13:01:46 [DEBUG] [aws-sdk-go] DEBUG: Validate Response ec2/DescribeDhcpOptions failed, not retrying, error InvalidDhcpOptionID.NotFound: The dhcpOption ID 'id-removed' does not exist                   
2018-04-06T13:01:46.772Z [DEBUG] plugin.terraform-provider-aws_v1.5.2:  status code: 400, request id: req-id-removed          
2018-04-06T13:01:46.772Z [DEBUG] plugin.terraform-provider-aws_v1.5.2: 2018/04/06 13:01:46 Error on DHCPOptionsStateRefresh: InvalidDhcpOptionID.NotFound: The dhcpOption ID 'id-removed' does not exist                                                    
2018-04-06T13:01:46.772Z [DEBUG] plugin.terraform-provider-aws_v1.5.2:  status code: 400, request id: req-id-removed          
2018/04/06 13:01:46 [TRACE] root.primary: eval: *terraform.EvalWriteState                                                     
2018/04/06 13:01:46 [ERROR] root.primary: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:                           

* aws_vpc_dhcp_options.this: Error waiting for DHCP Options (id-removed) to become available: InvalidDhcpOptionID.NotFound: The dhcpOption ID 'id-removed' does not exist                    
        status code: 400, request id: req-id-removed           
2018/04/06 13:01:46 [ERROR] root.primary: eval: *terraform.EvalSequence, err: 1 error(s) occurred:                            

* aws_vpc_dhcp_options.this: Error waiting for DHCP Options (id-removed) to become available: InvalidDhcpOptionID.NotFound: The dhcpOption ID 'id-removed' does not exist                    
        status code: 400, request id: req-id-removed           
2018/04/06 13:01:46 [TRACE] [walkApply] Exiting eval tree: module.primary.aws_vpc_dhcp_options.this

@ghost ghost added the size/XS Managed by automation to categorize the size of a PR. label Apr 10, 2018
@@ -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" {
Copy link
Contributor

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", "")
}

Copy link
Contributor

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.
@ghost ghost added size/S Managed by automation to categorize the size of a PR. and removed size/XS Managed by automation to categorize the size of a PR. labels Apr 10, 2018
@@ -212,7 +206,7 @@ func resourceAwsVpcDhcpOptionsDelete(d *schema.ResourceData, meta interface{}) e
}

switch ec2err.Code() {
case "InvalidDhcpOptionsID.NotFound":
case "InvalidDhcpOptionsID.NotFound", "InvalidDhcpOptionID.NotFound":
Copy link
Contributor Author

@gseyetik gseyetik Apr 10, 2018

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.

@gseyetik
Copy link
Contributor Author

@ewbankkit adjusted and updated throughout as suggested.

@bflad bflad added bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. labels Apr 12, 2018
@bflad bflad added this to the v1.15.0 milestone Apr 12, 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.

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)

@bflad bflad merged commit 8abf5fc into hashicorp:master Apr 12, 2018
bflad added a commit that referenced this pull request Apr 12, 2018
@bflad
Copy link
Contributor

bflad commented Apr 18, 2018

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.

@ghost
Copy link

ghost commented Apr 6, 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 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. size/S Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants