diff --git a/aws/resource_aws_cloudwatch_log_group.go b/aws/resource_aws_cloudwatch_log_group.go index 2c7cbc7dbe9..5132d97fcf7 100644 --- a/aws/resource_aws_cloudwatch_log_group.go +++ b/aws/resource_aws_cloudwatch_log_group.go @@ -159,7 +159,7 @@ func lookupCloudWatchLogGroup(conn *cloudwatchlogs.CloudWatchLogs, func resourceAwsCloudWatchLogGroupUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).cloudwatchlogsconn - name := d.Get("name").(string) + name := d.Id() log.Printf("[DEBUG] Updating CloudWatch Log Group: %q", name) if d.HasChange("retention_in_days") { diff --git a/aws/resource_aws_cloudwatch_log_group_test.go b/aws/resource_aws_cloudwatch_log_group_test.go index eceea130abf..525fef09dc9 100644 --- a/aws/resource_aws_cloudwatch_log_group_test.go +++ b/aws/resource_aws_cloudwatch_log_group_test.go @@ -50,6 +50,35 @@ func TestAccAWSCloudWatchLogGroup_namePrefix(t *testing.T) { }) } +func TestAccAWSCloudWatchLogGroup_namePrefix_retention(t *testing.T) { + var lg cloudwatchlogs.LogGroup + rName := acctest.RandString(5) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCloudWatchLogGroupDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCloudWatchLogGroup_namePrefix_retention(rName, 365), + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudWatchLogGroupExists("aws_cloudwatch_log_group.test", &lg), + resource.TestMatchResourceAttr("aws_cloudwatch_log_group.test", "name", regexp.MustCompile("^tf-test-")), + resource.TestCheckResourceAttr("aws_cloudwatch_log_group.test", "retention_in_days", "365"), + ), + }, + { + Config: testAccAWSCloudWatchLogGroup_namePrefix_retention(rName, 7), + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudWatchLogGroupExists("aws_cloudwatch_log_group.test", &lg), + resource.TestMatchResourceAttr("aws_cloudwatch_log_group.test", "name", regexp.MustCompile("^tf-test-")), + resource.TestCheckResourceAttr("aws_cloudwatch_log_group.test", "retention_in_days", "7"), + ), + }, + }, + }) +} + func TestAccAWSCloudWatchLogGroup_generatedName(t *testing.T) { var lg cloudwatchlogs.LogGroup @@ -413,6 +442,15 @@ resource "aws_cloudwatch_log_group" "test" { } ` +func testAccAWSCloudWatchLogGroup_namePrefix_retention(rName string, retention int) string { + return fmt.Sprintf(` +resource "aws_cloudwatch_log_group" "test" { + name_prefix = "tf-test-%s" + retention_in_days = %d +} +`, rName, retention) +} + const testAccAWSCloudWatchLogGroup_generatedName = ` resource "aws_cloudwatch_log_group" "test" {} `