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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions aws/resource_aws_vpc_dhcp_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down Expand Up @@ -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.

return nil
case "DependencyViolation":
// If it is a dependency violation, we want to disassociate
Expand Down Expand Up @@ -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() == "InvalidDhcpOptionsID.NotFound" {
if isNoSuchDhcpOptionIDErr(err) {
resp = nil
} else {
log.Printf("Error on DHCPOptionsStateRefresh: %s", err)
Expand All @@ -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", "")
}