Skip to content

Commit

Permalink
provider/aws: Add CertificateNotFound retry waiter to aws_alb_listener (
Browse files Browse the repository at this point in the history
hashicorp#10180)

Looks like sometimes it takes some time for IAM certificates to
propagate, which can cause errors on ALB listener creation.
Possibly same thing as hashicorp#5178, but for ALB
now instead of ELB.

This was discovered via acceptance tests, specifically the
TestAccAWSALBListener_https test. Updated the creation process to wait
on CertificateNotFound for a max of 5min.
  • Loading branch information
vancluever authored and Gustavo Mateus committed Dec 6, 2016
1 parent 7a96888 commit 35bc7de
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions builtin/providers/aws/resource_aws_alb_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"fmt"
"log"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/elbv2"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down Expand Up @@ -86,8 +88,10 @@ func resourceAwsAlbListener() *schema.Resource {
func resourceAwsAlbListenerCreate(d *schema.ResourceData, meta interface{}) error {
elbconn := meta.(*AWSClient).elbv2conn

albArn := d.Get("load_balancer_arn").(string)

params := &elbv2.CreateListenerInput{
LoadBalancerArn: aws.String(d.Get("load_balancer_arn").(string)),
LoadBalancerArn: aws.String(albArn),
Port: aws.Int64(int64(d.Get("port").(int))),
Protocol: aws.String(d.Get("protocol").(string)),
}
Expand Down Expand Up @@ -116,7 +120,25 @@ func resourceAwsAlbListenerCreate(d *schema.ResourceData, meta interface{}) erro
}
}

resp, err := elbconn.CreateListener(params)
var resp *elbv2.CreateListenerOutput

err := resource.Retry(5*time.Minute, func() *resource.RetryError {
var err error
log.Printf("[DEBUG] Creating ALB listener for ARN: %s", d.Get("load_balancer_arn").(string))
resp, err = elbconn.CreateListener(params)
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "CertificateNotFound" {
log.Printf("[WARN] Got an error while trying to create ALB listener for ARN: %s: %s", albArn, err)
return resource.RetryableError(err)
}
}
if err != nil {
return resource.NonRetryableError(err)
}

return nil
})

if err != nil {
return errwrap.Wrapf("Error creating ALB Listener: {{err}}", err)
}
Expand Down

0 comments on commit 35bc7de

Please sign in to comment.