From 8e91b7347e9cfa93964cf69d9c791c5161593a60 Mon Sep 17 00:00:00 2001 From: Gideon Seyetik Date: Mon, 9 Apr 2018 22:49:24 -0400 Subject: [PATCH 1/2] Update not found error message for DescribeDhcpOptions. --- aws/resource_aws_vpc_dhcp_options.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_vpc_dhcp_options.go b/aws/resource_aws_vpc_dhcp_options.go index ec2844cc7c6..729b97df466 100644 --- a/aws/resource_aws_vpc_dhcp_options.go +++ b/aws/resource_aws_vpc_dhcp_options.go @@ -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" { resp = nil } else { log.Printf("Error on DHCPOptionsStateRefresh: %s", err) From 07d0f55814ff306774c4ec2f77e526eb818264a7 Mon Sep 17 00:00:00 2001 From: Gideon Seyetik Date: Tue, 10 Apr 2018 10:10:30 -0400 Subject: [PATCH 2/2] Expanded support for not found messages with DhcpOptions. Capture both "InvalidDhcpOptionID.NotFound" and "InvalidDhcpOptionsID.NotFound" in all locations that refrenced either error. --- aws/resource_aws_vpc_dhcp_options.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/aws/resource_aws_vpc_dhcp_options.go b/aws/resource_aws_vpc_dhcp_options.go index 729b97df466..b2334b91aa3 100644 --- a/aws/resource_aws_vpc_dhcp_options.go +++ b/aws/resource_aws_vpc_dhcp_options.go @@ -147,17 +147,11 @@ func resourceAwsVpcDhcpOptionsRead(d *schema.ResourceData, meta interface{}) err resp, err := conn.DescribeDhcpOptions(req) if err != nil { - ec2err, ok := err.(awserr.Error) - if !ok { - return fmt.Errorf("Error retrieving DHCP Options: %s", err.Error()) - } - - if ec2err.Code() == "InvalidDhcpOptionID.NotFound" { + if isNoSuchDhcpOptionIDErr(err) { log.Printf("[WARN] DHCP Options (%s) not found, removing from state", d.Id()) d.SetId("") return nil } - return fmt.Errorf("Error retrieving DHCP Options: %s", err.Error()) } @@ -212,7 +206,7 @@ func resourceAwsVpcDhcpOptionsDelete(d *schema.ResourceData, meta interface{}) e } switch ec2err.Code() { - case "InvalidDhcpOptionsID.NotFound": + case "InvalidDhcpOptionsID.NotFound", "InvalidDhcpOptionID.NotFound": return nil case "DependencyViolation": // If it is a dependency violation, we want to disassociate @@ -272,7 +266,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() == "InvalidDhcpOptionID.NotFound" { + if isNoSuchDhcpOptionIDErr(err) { resp = nil } else { log.Printf("Error on DHCPOptionsStateRefresh: %s", err) @@ -290,3 +284,7 @@ func resourceDHCPOptionsStateRefreshFunc(conn *ec2.EC2, id string) resource.Stat return dos, "created", nil } } + +func isNoSuchDhcpOptionIDErr(err error) bool { + return isAWSErr(err, "InvalidDhcpOptionID.NotFound", "") || isAWSErr(err, "InvalidDhcpOptionsID.NotFound", "") +}