Skip to content

Commit

Permalink
Merge pull request #6776 from ahl/aws_cloudwatch_log_stream
Browse files Browse the repository at this point in the history
can't destroy aws_cloudwatch_log_stream if group has been destroyed
  • Loading branch information
bflad authored Dec 17, 2018
2 parents bbd4ede + f7feb13 commit 533c68f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
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

0 comments on commit 533c68f

Please sign in to comment.