Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry InvalidTarget errors for AWS LB target group attachment. #8538

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 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,19 @@ 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 err != nil {
return fmt.Errorf("Error registering targets with target group: %s", err)
}
Expand Down