From a0bb67a2f3ed6f64d6dd1a1606714790aabe84be Mon Sep 17 00:00:00 2001 From: "Adam H. Leventhal" Date: Fri, 7 Dec 2018 22:18:10 -0800 Subject: [PATCH 1/3] add failing test --- ...resource_aws_cloudwatch_log_stream_test.go | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/aws/resource_aws_cloudwatch_log_stream_test.go b/aws/resource_aws_cloudwatch_log_stream_test.go index 4c2c16c64ba..75d34106a77 100644 --- a/aws/resource_aws_cloudwatch_log_stream_test.go +++ b/aws/resource_aws_cloudwatch_log_stream_test.go @@ -65,6 +65,40 @@ func testAccCheckCloudWatchLogStreamDisappears(ls *cloudwatchlogs.LogStream, lgn } } +func TestAccAWSCloudWatchLogStream_disappears2(t *testing.T) { + var ls cloudwatchlogs.LogStream + 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), + testAccCheckCloudWatchLogStreamDisappears2(&ls, rName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func testAccCheckCloudWatchLogStreamDisappears2(ls *cloudwatchlogs.LogStream, lgn string) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).cloudwatchlogsconn + opts := &cloudwatchlogs.DeleteLogGroupInput{ + LogGroupName: aws.String(lgn), + } + if _, err := conn.DeleteLogGroup(opts); err != nil { + return err + } + return nil + } +} + func testAccCheckCloudWatchLogStreamExists(n string, ls *cloudwatchlogs.LogStream) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] From 86032443ed41bdc94eda61f9b45d1b9bb1ee02b5 Mon Sep 17 00:00:00 2001 From: "Adam H. Leventhal" Date: Wed, 5 Dec 2018 16:33:13 -0800 Subject: [PATCH 2/3] can't destroy aws_cloudwatch_log_stream if group has been destroyed --- aws/resource_aws_cloudwatch_log_stream.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/aws/resource_aws_cloudwatch_log_stream.go b/aws/resource_aws_cloudwatch_log_stream.go index 48b409967f7..e7e1927698b 100644 --- a/aws/resource_aws_cloudwatch_log_stream.go +++ b/aws/resource_aws_cloudwatch_log_stream.go @@ -58,9 +58,17 @@ 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 + _, err2 := lookupCloudWatchLogGroup(conn, group) + if err2 != nil { + return err + } + + log.Printf("[DEBUG] container CloudWatch group %q Not Found.", group) + exists = false } if !exists { From f7feb131c0d800551a4aa24d411336c136aae47c Mon Sep 17 00:00:00 2001 From: "Adam H. Leventhal" Date: Sat, 15 Dec 2018 22:52:35 -0800 Subject: [PATCH 3/3] review feedback --- aws/resource_aws_cloudwatch_log_stream.go | 3 +-- ...resource_aws_cloudwatch_log_stream_test.go | 19 ++++--------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/aws/resource_aws_cloudwatch_log_stream.go b/aws/resource_aws_cloudwatch_log_stream.go index e7e1927698b..666f7ad58a6 100644 --- a/aws/resource_aws_cloudwatch_log_stream.go +++ b/aws/resource_aws_cloudwatch_log_stream.go @@ -62,8 +62,7 @@ func resourceAwsCloudWatchLogStreamRead(d *schema.ResourceData, meta interface{} ls, exists, err := lookupCloudWatchLogStream(conn, d.Id(), group, nil) if err != nil { - _, err2 := lookupCloudWatchLogGroup(conn, group) - if err2 != nil { + if !isAWSErr(err, cloudwatchlogs.ErrCodeResourceNotFoundException, "") { return err } diff --git a/aws/resource_aws_cloudwatch_log_stream_test.go b/aws/resource_aws_cloudwatch_log_stream_test.go index 75d34106a77..f30024545e4 100644 --- a/aws/resource_aws_cloudwatch_log_stream_test.go +++ b/aws/resource_aws_cloudwatch_log_stream_test.go @@ -65,8 +65,9 @@ func testAccCheckCloudWatchLogStreamDisappears(ls *cloudwatchlogs.LogStream, lgn } } -func TestAccAWSCloudWatchLogStream_disappears2(t *testing.T) { +func TestAccAWSCloudWatchLogStream_disappears_LogGroup(t *testing.T) { var ls cloudwatchlogs.LogStream + var lg cloudwatchlogs.LogGroup rName := acctest.RandString(15) resource.ParallelTest(t, resource.TestCase{ @@ -78,7 +79,8 @@ func TestAccAWSCloudWatchLogStream_disappears2(t *testing.T) { Config: testAccAWSCloudWatchLogStreamConfig(rName), Check: resource.ComposeTestCheckFunc( testAccCheckCloudWatchLogStreamExists("aws_cloudwatch_log_stream.foobar", &ls), - testAccCheckCloudWatchLogStreamDisappears2(&ls, rName), + testAccCheckCloudWatchLogGroupExists("aws_cloudwatch_log_group.foobar", &lg), + testAccCheckCloudWatchLogGroupDisappears(&lg), ), ExpectNonEmptyPlan: true, }, @@ -86,19 +88,6 @@ func TestAccAWSCloudWatchLogStream_disappears2(t *testing.T) { }) } -func testAccCheckCloudWatchLogStreamDisappears2(ls *cloudwatchlogs.LogStream, lgn string) resource.TestCheckFunc { - return func(s *terraform.State) error { - conn := testAccProvider.Meta().(*AWSClient).cloudwatchlogsconn - opts := &cloudwatchlogs.DeleteLogGroupInput{ - LogGroupName: aws.String(lgn), - } - if _, err := conn.DeleteLogGroup(opts); err != nil { - return err - } - return nil - } -} - func testAccCheckCloudWatchLogStreamExists(n string, ls *cloudwatchlogs.LogStream) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n]