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

resource/aws_cloudwatch_log_stream: Prevent early state removal #11617

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
21 changes: 20 additions & 1 deletion aws/resource_aws_cloudwatch_log_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"fmt"
"log"
"regexp"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

Expand Down Expand Up @@ -60,7 +62,24 @@ func resourceAwsCloudWatchLogStreamRead(d *schema.ResourceData, meta interface{}

group := d.Get("log_group_name").(string)

ls, exists, err := lookupCloudWatchLogStream(conn, d.Id(), group, nil)
var ls *cloudwatchlogs.LogStream
var exists bool

err := resource.Retry(2*time.Minute, func() *resource.RetryError {
Copy link
Contributor Author

@camlow325 camlow325 Jan 16, 2020

Choose a reason for hiding this comment

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

I'm not really sure what a good upper bound for the retry timeout would be. In automation today, we do a second Terraform apply after the first one fails and that has always failed with a ResourceAlreadyExistsException: The specified log stream already exists error. The second run probably completes in well under 2 minutes in most cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

Two minutes is pretty reasonable 👍 We can/will likely add a constant for this in the future.

var err error
ls, exists, err = lookupCloudWatchLogStream(conn, d.Id(), group, nil)
if err != nil {
return resource.NonRetryableError(err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe it would be good to retry for other kinds of error, too - not sure. For the cases we've seen so far that we'd benefit from retrying on, the initial lookup returns a 200 OK so not retrying on failures would be backward compatible.

}
if d.IsNewResource() && !exists {
return resource.RetryableError(&resource.NotFoundError{})
}
return nil
})
if isResourceTimeoutError(err) {
ls, exists, err = lookupCloudWatchLogStream(conn, d.Id(), group, nil)
}

if err != nil {
if !isAWSErr(err, cloudwatchlogs.ErrCodeResourceNotFoundException, "") {
return err
Expand Down