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

can't destroy aws_cloudwatch_log_stream if group has been destroyed #6776

Merged
merged 3 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions aws/resource_aws_cloudwatch_log_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,16 @@ func resourceAwsCloudWatchLogStreamCreate(d *schema.ResourceData, meta interface
func resourceAwsCloudWatchLogStreamRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).cloudwatchlogsconn

ls, exists, err := lookupCloudWatchLogStream(conn, d.Id(), d.Get("log_group_name").(string), nil)
group := d.Get("log_group_name").(string)

ls, exists, err := lookupCloudWatchLogStream(conn, d.Id(), group, nil)
if err != nil {
return err
if !isAWSErr(err, cloudwatchlogs.ErrCodeResourceNotFoundException, "") {
return err
}

log.Printf("[DEBUG] container CloudWatch group %q Not Found.", group)
exists = false
}

if !exists {
Expand Down
23 changes: 23 additions & 0 deletions aws/resource_aws_cloudwatch_log_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,29 @@ func testAccCheckCloudWatchLogStreamDisappears(ls *cloudwatchlogs.LogStream, lgn
}
}

func TestAccAWSCloudWatchLogStream_disappears_LogGroup(t *testing.T) {
var ls cloudwatchlogs.LogStream
var lg cloudwatchlogs.LogGroup
rName := acctest.RandString(15)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSCloudWatchLogStreamDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSCloudWatchLogStreamConfig(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudWatchLogStreamExists("aws_cloudwatch_log_stream.foobar", &ls),
testAccCheckCloudWatchLogGroupExists("aws_cloudwatch_log_group.foobar", &lg),
testAccCheckCloudWatchLogGroupDisappears(&lg),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func testAccCheckCloudWatchLogStreamExists(n string, ls *cloudwatchlogs.LogStream) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down