Skip to content

Commit

Permalink
Merge pull request #8538 from jbarrick-mesosphere/aws-lb-invalid-target
Browse files Browse the repository at this point in the history
  • Loading branch information
gdavison committed Feb 19, 2021
2 parents 6208518 + 98ea29d commit 40fc7a6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/8538.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_lb_target_group_attachment: Retry InvalidTarget errors when creating
```
18 changes: 17 additions & 1 deletion aws/resource_aws_lb_target_group_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/elbv2"
Expand Down Expand Up @@ -67,7 +68,22 @@ func resourceAwsLbAttachmentCreate(d *schema.ResourceData, meta interface{}) err
log.Printf("[INFO] Registering Target %s with Target Group %s", d.Get("target_id").(string),
d.Get("target_group_arn").(string))

_, err := elbconn.RegisterTargets(params)
err := resource.Retry(10*time.Minute, func() *resource.RetryError {
_, err := elbconn.RegisterTargets(params)

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

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

return nil
})
if isResourceTimeoutError(err) {
_, err = elbconn.RegisterTargets(params)
}
if err != nil {
return fmt.Errorf("Error registering targets with target group: %s", err)
}
Expand Down

0 comments on commit 40fc7a6

Please sign in to comment.