Skip to content

Commit

Permalink
Merge pull request #9765 from terraform-providers/rfd-retry-elb
Browse files Browse the repository at this point in the history
Final retries for ELB resources
  • Loading branch information
ryndaniels authored Aug 16, 2019
2 parents 5fa2372 + 5b6ca72 commit d99e0f1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
39 changes: 22 additions & 17 deletions aws/resource_aws_elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,11 @@ func resourceAwsElbCreate(d *schema.ResourceData, meta interface{}) error {
}
return nil
})

if isResourceTimeoutError(err) {
_, err = elbconn.CreateLoadBalancer(elbOpts)
}
if err != nil {
return err
return fmt.Errorf("Error creating ELB: %s", err)
}

// Assign the elb's unique identifier for use later
Expand Down Expand Up @@ -511,16 +513,15 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
// other listeners on the ELB. Retry here to eliminate that.
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
log.Printf("[DEBUG] ELB Create Listeners opts: %s", createListenersOpts)
if _, err := elbconn.CreateLoadBalancerListeners(createListenersOpts); err != nil {
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "DuplicateListener" {
log.Printf("[DEBUG] Duplicate listener found for ELB (%s), retrying", d.Id())
return resource.RetryableError(awsErr)
}
if awsErr.Code() == "CertificateNotFound" && strings.Contains(awsErr.Message(), "Server Certificate not found for the key: arn") {
log.Printf("[DEBUG] SSL Cert not found for given ARN, retrying")
return resource.RetryableError(awsErr)
}
_, err := elbconn.CreateLoadBalancerListeners(createListenersOpts)
if err != nil {
if isAWSErr(err, "DuplicateListener", "") {
log.Printf("[DEBUG] Duplicate listener found for ELB (%s), retrying", d.Id())
return resource.RetryableError(err)
}
if isAWSErr(err, "CertificateNotFound", "Server Certificate not found for the key: arn") {
log.Printf("[DEBUG] SSL Cert not found for given ARN, retrying")
return resource.RetryableError(err)
}

// Didn't recognize the error, so shouldn't retry.
Expand All @@ -529,6 +530,9 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
// Successful creation
return nil
})
if isResourceTimeoutError(err) {
_, err = elbconn.CreateLoadBalancerListeners(createListenersOpts)
}
if err != nil {
return fmt.Errorf("Failure adding new or updated ELB listeners: %s", err)
}
Expand Down Expand Up @@ -765,18 +769,19 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := elbconn.AttachLoadBalancerToSubnets(attachOpts)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
if isAWSErr(err, "InvalidConfigurationRequest", "cannot be attached to multiple subnets in the same AZ") {
// eventually consistent issue with removing a subnet in AZ1 and
// immediately adding a new one in the same AZ
if awsErr.Code() == "InvalidConfigurationRequest" && strings.Contains(awsErr.Message(), "cannot be attached to multiple subnets in the same AZ") {
log.Printf("[DEBUG] retrying az association")
return resource.RetryableError(awsErr)
}
log.Printf("[DEBUG] retrying az association")
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if isResourceTimeoutError(err) {
_, err = elbconn.AttachLoadBalancerToSubnets(attachOpts)
}
if err != nil {
return fmt.Errorf("Failure adding ELB subnets: %s", err)
}
Expand Down
4 changes: 3 additions & 1 deletion aws/resource_aws_elb_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ func resourceAwsElbAttachmentCreate(d *schema.ResourceData, meta interface{}) er

return nil
})

if isResourceTimeoutError(err) {
_, err = elbconn.RegisterInstancesWithLoadBalancer(&registerInstancesOpts)
}
if err != nil {
return fmt.Errorf("Failure registering instances with ELB: %s", err)
}
Expand Down

0 comments on commit d99e0f1

Please sign in to comment.