Skip to content

Commit

Permalink
resource/cloudwatch_log_group: Use ID as name (hashicorp#2190)
Browse files Browse the repository at this point in the history
* Use ID as name

* Add update section in test, replace indent with spaces
  • Loading branch information
atsushi-ishibashi authored and Ninir committed Nov 7, 2017
1 parent 0319fef commit 6a3d5c6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aws/resource_aws_cloudwatch_log_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
38 changes: 38 additions & 0 deletions aws/resource_aws_cloudwatch_log_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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" {}
`

0 comments on commit 6a3d5c6

Please sign in to comment.