Skip to content

Commit

Permalink
resource/aws_elb_attachment: Retry ELB attachment on InvalidTarget
Browse files Browse the repository at this point in the history
…error (#8483)

#7561 - Retry ELB attachment on InvalidTarget.
  • Loading branch information
nywilken authored May 2, 2019
2 parents 402db8f + 0fd6b28 commit c942fb8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion aws/resource_aws_elb_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"fmt"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/elb"
Expand Down Expand Up @@ -45,7 +46,20 @@ func resourceAwsElbAttachmentCreate(d *schema.ResourceData, meta interface{}) er

log.Printf("[INFO] registering instance %s with ELB %s", instance, elbName)

_, err := elbconn.RegisterInstancesWithLoadBalancer(&registerInstancesOpts)
err := resource.Retry(10*time.Minute, func() *resource.RetryError {
_, err := elbconn.RegisterInstancesWithLoadBalancer(&registerInstancesOpts)

if isAWSErr(err, "InvalidTarget", "") {
return resource.RetryableError(fmt.Errorf("Error attaching instance to ELB, retrying: %s", err))
}

if err != nil {
return resource.NonRetryableError(err)
}

return nil
})

if err != nil {
return fmt.Errorf("Failure registering instances with ELB: %s", err)
}
Expand Down

0 comments on commit c942fb8

Please sign in to comment.