From 0b894e4716c3815b0d9198c14141eb64b1e3f473 Mon Sep 17 00:00:00 2001 From: Ryn Daniels Date: Thu, 15 Aug 2019 17:26:15 +0200 Subject: [PATCH] Final retries for LB resources --- aws/resource_aws_lb.go | 50 ++++++++++++++------- aws/resource_aws_lb_listener_certificate.go | 3 ++ aws/resource_aws_lb_listener_rule.go | 17 +++++-- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/aws/resource_aws_lb.go b/aws/resource_aws_lb.go index 2860d051cf8..7817fbe8803 100644 --- a/aws/resource_aws_lb.go +++ b/aws/resource_aws_lb.go @@ -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) } @@ -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) { diff --git a/aws/resource_aws_lb_listener_certificate.go b/aws/resource_aws_lb_listener_certificate.go index 51405e30fb1..5ab93c07f16 100644 --- a/aws/resource_aws_lb_listener_certificate.go +++ b/aws/resource_aws_lb_listener_certificate.go @@ -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) diff --git a/aws/resource_aws_lb_listener_rule.go b/aws/resource_aws_lb_listener_rule.go index a6edf22937e..873398ac49a 100644 --- a/aws/resource_aws_lb_listener_rule.go +++ b/aws/resource_aws_lb_listener_rule.go @@ -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) } @@ -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") } @@ -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())