Skip to content

Commit

Permalink
update waitUntilElbDeleted function to only return success on LoadBal…
Browse files Browse the repository at this point in the history
…ancerNotFound error
  • Loading branch information
tonerdo committed Feb 7, 2018
1 parent 9169791 commit fa51aa5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 8 additions & 3 deletions aws/elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"time"

"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/elb"
"github.com/gruntwork-io/aws-nuke/logging"
Expand All @@ -13,14 +14,18 @@ func waitUntilElbDeleted(svc *elb.ELB, input *elb.DescribeLoadBalancersInput) er
for i := 0; i < 30; i++ {
_, err := svc.DescribeLoadBalancers(input)
if err != nil {
// an error is returned when ELB no longer exists
return nil
if awsErr, isAwsErr := err.(awserr.Error); isAwsErr && awsErr.Code() == "LoadBalancerNotFound" {
return nil
}

return err
}

time.Sleep(1 * time.Second)
logging.Logger.Debug("Waiting for ELB to be deleted")
}

panic("ELBs failed to delete")
return ElbDeleteError{}
}

// Returns a formatted string of ELB names
Expand Down
6 changes: 6 additions & 0 deletions aws/elb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ func (balancer LoadBalancers) Nuke(session *session.Session) error {

return nil
}

type ElbDeleteError struct{}

func (e ElbDeleteError) Error() string {
return "ELB was not deleted"
}

0 comments on commit fa51aa5

Please sign in to comment.