diff --git a/aws/resource_aws_cloudwatch_log_stream.go b/aws/resource_aws_cloudwatch_log_stream.go index 48b409967f7..666f7ad58a6 100644 --- a/aws/resource_aws_cloudwatch_log_stream.go +++ b/aws/resource_aws_cloudwatch_log_stream.go @@ -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 { diff --git a/aws/resource_aws_cloudwatch_log_stream_test.go b/aws/resource_aws_cloudwatch_log_stream_test.go index 4c2c16c64ba..f30024545e4 100644 --- a/aws/resource_aws_cloudwatch_log_stream_test.go +++ b/aws/resource_aws_cloudwatch_log_stream_test.go @@ -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]