From 0e0f74ef20d77b94c059971928c7976803ae834a Mon Sep 17 00:00:00 2001 From: "jbarrick@mesosphere.com" Date: Mon, 29 Apr 2019 14:10:26 -0700 Subject: [PATCH 1/2] #7561 - Retry ELB attachment on InvalidTarget. --- aws/resource_aws_elb_attachment.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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) } From 0fd6b28789af2cde1be9887ae03413748048a598 Mon Sep 17 00:00:00 2001 From: "jbarrick@mesosphere.com" Date: Wed, 1 May 2019 15:36:56 -0700 Subject: [PATCH 2/2] Address review comments --- aws/resource_aws_elb_attachment.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/aws/resource_aws_elb_attachment.go b/aws/resource_aws_elb_attachment.go index 51c8a6b2066..32b02eec9c9 100644 --- a/aws/resource_aws_elb_attachment.go +++ b/aws/resource_aws_elb_attachment.go @@ -6,7 +6,6 @@ import ( "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" @@ -47,18 +46,17 @@ func resourceAwsElbAttachmentCreate(d *schema.ResourceData, meta interface{}) er log.Printf("[INFO] registering instance %s with ELB %s", instance, elbName) - err := resource.Retry(600*time.Second, func() *resource.RetryError { + err := resource.Retry(10*time.Minute, func() *resource.RetryError { _, err := elbconn.RegisterInstancesWithLoadBalancer(®isterInstancesOpts) + if isAWSErr(err, "InvalidTarget", "") { + return resource.RetryableError(fmt.Errorf("Error attaching instance to ELB, retrying: %s", err)) + } + 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 })