Skip to content

Commit

Permalink
hashicorp#7561 - Retry ELB attachment on InvalidTarget.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarrick-mesosphere committed Apr 29, 2019
1 parent 3cdd3a6 commit 0e0f74e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion aws/resource_aws_elb_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package aws
import (
"fmt"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/elb"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -45,7 +47,21 @@ 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(600*time.Second, func() *resource.RetryError {
_, err := elbconn.RegisterInstancesWithLoadBalancer(&registerInstancesOpts)

if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "InvalidTarget" {
return resource.RetryableError(
fmt.Errorf("Error attaching instance to ELB, retrying: %s", err))
}
}
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 0e0f74e

Please sign in to comment.