diff --git a/aws/resource_aws_elb_attachment.go b/aws/resource_aws_elb_attachment.go index 119c4e663a4..51c8a6b2066 100644 --- a/aws/resource_aws_elb_attachment.go +++ b/aws/resource_aws_elb_attachment.go @@ -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" @@ -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(®isterInstancesOpts) + err := resource.Retry(600*time.Second, func() *resource.RetryError { + _, err := elbconn.RegisterInstancesWithLoadBalancer(®isterInstancesOpts) + + 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) }