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

aws_lb_listener: wait for listener creation #5167

Merged
merged 1 commit into from
Oct 9, 2018
Merged
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
23 changes: 21 additions & 2 deletions aws/resource_aws_lb_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func resourceAwsLbListener() *schema.Resource {
State: schema.ImportStatePassthrough,
},

Timeouts: &schema.ResourceTimeout{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do decide to add user configurable timeouts for the resource (I would recommend against in this situation), it should be documented in the resource documentation under a ## Timeouts header.

Read: schema.DefaultTimeout(10 * time.Minute),
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Expand Down Expand Up @@ -151,11 +155,26 @@ func resourceAwsLbListenerCreate(d *schema.ResourceData, meta interface{}) error
func resourceAwsLbListenerRead(d *schema.ResourceData, meta interface{}) error {
elbconn := meta.(*AWSClient).elbv2conn

resp, err := elbconn.DescribeListeners(&elbv2.DescribeListenersInput{
var resp *elbv2.DescribeListenersOutput
var request = &elbv2.DescribeListenersInput{
ListenerArns: []*string{aws.String(d.Id())},
}

err := resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When dealing with AWS service eventual consistency, we prefer to hardcode 1 minute timeouts. Generally its not desired to allow that timeout to be user configurable as its a knob that is unlikely to handle the situation properly by waiting longer.

var err error
resp, err = elbconn.DescribeListeners(request)
if err != nil {
if d.IsNewResource() && isAWSErr(err, elbv2.ErrCodeListenerNotFoundException, "") {
return resource.RetryableError(err)
} else {
return resource.NonRetryableError(err)
}
}
return nil
})

if err != nil {
if isAWSErr(err, elbv2.ErrCodeListenerNotFoundException, "") {
if !d.IsNewResource() && isAWSErr(err, elbv2.ErrCodeListenerNotFoundException, "") {
log.Printf("[WARN] DescribeListeners - removing %s from state", d.Id())
d.SetId("")
return nil
Expand Down