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

Final retries for LB resources #9787

Merged
merged 1 commit into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
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
50 changes: 33 additions & 17 deletions aws/resource_aws_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,24 +580,26 @@ func waitForNLBNetworkInterfacesToDetach(conn *ec2.EC2, lbArn string) error {
// We cannot cleanup these ENIs ourselves as that would result in
// OperationNotPermitted: You are not allowed to manage 'ela-attach' attachments.
// yet presence of these ENIs may prevent us from deleting EIPs associated w/ the NLB

return resource.Retry(5*time.Minute, func() *resource.RetryError {
out, err := conn.DescribeNetworkInterfaces(&ec2.DescribeNetworkInterfacesInput{
Filters: []*ec2.Filter{
{
Name: aws.String("attachment.instance-owner-id"),
Values: []*string{aws.String("amazon-aws")},
},
{
Name: aws.String("attachment.attachment-id"),
Values: []*string{aws.String("ela-attach-*")},
},
{
Name: aws.String("description"),
Values: []*string{aws.String("ELB " + name)},
},
input := &ec2.DescribeNetworkInterfacesInput{
Filters: []*ec2.Filter{
{
Name: aws.String("attachment.instance-owner-id"),
Values: []*string{aws.String("amazon-aws")},
},
})
{
Name: aws.String("attachment.attachment-id"),
Values: []*string{aws.String("ela-attach-*")},
},
{
Name: aws.String("description"),
Values: []*string{aws.String("ELB " + name)},
},
},
}
var out *ec2.DescribeNetworkInterfacesOutput
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
var err error
out, err = conn.DescribeNetworkInterfaces(input)
if err != nil {
return resource.NonRetryableError(err)
}
Expand All @@ -611,6 +613,20 @@ func waitForNLBNetworkInterfacesToDetach(conn *ec2.EC2, lbArn string) error {

return nil
})
if isResourceTimeoutError(err) {
out, err = conn.DescribeNetworkInterfaces(input)
if err != nil {
return fmt.Errorf("Error describing network inferfaces: %s", err)
}
niCount := len(out.NetworkInterfaces)
if niCount > 0 {
return fmt.Errorf("Error waiting for %d ENIs of %q to clean up", niCount, lbArn)
}
}
if err != nil {
return fmt.Errorf("Error describing network inferfaces: %s", err)
}
return nil
}

func getLbNameFromArn(arn string) (string, error) {
Expand Down
3 changes: 3 additions & 0 deletions aws/resource_aws_lb_listener_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ func resourceAwsLbListenerCertificateRead(d *schema.ResourceData, meta interface

return nil
})
if isResourceTimeoutError(err) {
certificate, err = findAwsLbListenerCertificate(certificateArn, listenerArn, true, nil, conn)
}
if err != nil {
if certificate == nil {
log.Printf("[WARN] %s - removing from state", err)
Expand Down
17 changes: 14 additions & 3 deletions aws/resource_aws_lb_listener_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,10 @@ func resourceAwsLbListenerRuleCreate(d *schema.ResourceData, meta interface{}) e
return fmt.Errorf("Error creating LB Listener Rule: %v", err)
}
} else {
var priority int64
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
var err error
priority, err := highestListenerRulePriority(elbconn, listenerArn)
priority, err = highestListenerRulePriority(elbconn, listenerArn)
if err != nil {
return resource.NonRetryableError(err)
}
Expand All @@ -491,12 +492,20 @@ func resourceAwsLbListenerRuleCreate(d *schema.ResourceData, meta interface{}) e
}
return nil
})
if isResourceTimeoutError(err) {
priority, err = highestListenerRulePriority(elbconn, listenerArn)
if err != nil {
return fmt.Errorf("Error getting highest listener rule priority: %s", err)
}
params.Priority = aws.Int64(priority + 1)
resp, err = elbconn.CreateRule(params)
}
if err != nil {
return fmt.Errorf("Error creating LB Listener Rule: %v", err)
}
}

if len(resp.Rules) == 0 {
if resp == nil || len(resp.Rules) == 0 {
return errors.New("Error creating LB Listener Rule: no rules returned in response")
}

Expand Down Expand Up @@ -525,7 +534,9 @@ func resourceAwsLbListenerRuleRead(d *schema.ResourceData, meta interface{}) err
}
return nil
})

if isResourceTimeoutError(err) {
resp, err = elbconn.DescribeRules(req)
}
if err != nil {
if isAWSErr(err, elbv2.ErrCodeRuleNotFoundException, "") {
log.Printf("[WARN] DescribeRules - removing %s from state", d.Id())
Expand Down