Skip to content

Commit

Permalink
Merge pull request #34679 from kylewintaur/f-cloudwatch-logs-log-classes
Browse files Browse the repository at this point in the history
Add Cloudwatch Logs log classes argument
  • Loading branch information
ewbankkit committed Dec 1, 2023
2 parents dc16368 + 33cfdc8 commit 8c993e5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/34679.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_cloudwatch_log_group: Add `log_group_class` argument
```
14 changes: 12 additions & 2 deletions internal/service/logs/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/enum"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
Expand Down Expand Up @@ -45,6 +46,13 @@ func resourceGroup() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"log_group_class": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: types.LogGroupClassStandard,
ValidateDiagFunc: enum.Validate[types.LogGroupClass](),
},
"name": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -85,8 +93,9 @@ func resourceGroupCreate(ctx context.Context, d *schema.ResourceData, meta inter

name := create.Name(d.Get("name").(string), d.Get("name_prefix").(string))
input := &cloudwatchlogs.CreateLogGroupInput{
LogGroupName: aws.String(name),
Tags: getTagsIn(ctx),
LogGroupClass: types.LogGroupClass(d.Get("log_group_class").(string)),
LogGroupName: aws.String(name),
Tags: getTagsIn(ctx),
}

if v, ok := d.GetOk("kms_key_id"); ok {
Expand Down Expand Up @@ -136,6 +145,7 @@ func resourceGroupRead(ctx context.Context, d *schema.ResourceData, meta interfa

d.Set("arn", TrimLogGroupARNWildcardSuffix(aws.ToString(lg.Arn)))
d.Set("kms_key_id", lg.KmsKeyId)
d.Set("log_group_class", lg.LogGroupClass)
d.Set("name", lg.LogGroupName)
d.Set("name_prefix", create.NamePrefixFromName(aws.ToString(lg.LogGroupName)))
d.Set("retention_in_days", lg.RetentionInDays)
Expand Down
33 changes: 33 additions & 0 deletions internal/service/logs/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestAccLogsGroup_basic(t *testing.T) {
testAccCheckGroupExists(ctx, t, resourceName, &v),
acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "logs", fmt.Sprintf("log-group:%s", rName)),
resource.TestCheckResourceAttr(resourceName, "kms_key_id", ""),
resource.TestCheckResourceAttr(resourceName, "log_group_class", "STANDARD"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "name_prefix", ""),
resource.TestCheckResourceAttr(resourceName, "retention_in_days", "0"),
Expand Down Expand Up @@ -227,6 +228,29 @@ func TestAccLogsGroup_kmsKey(t *testing.T) {
})
}

func TestAccLogsGroup_logGroupClass(t *testing.T) {
ctx := acctest.Context(t)
var v types.LogGroup
rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix)
resourceName := "aws_cloudwatch_log_group.test"

acctest.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.CloudWatchLogsEndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckGroupDestroy(ctx, t),
Steps: []resource.TestStep{
{
Config: testAccGroupConfig_logGroupClass(rName, "INFREQUENT_ACCESS"),
Check: resource.ComposeTestCheckFunc(
testAccCheckGroupExists(ctx, t, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "log_group_class", "INFREQUENT_ACCESS"),
),
},
},
})
}

func TestAccLogsGroup_retentionPolicy(t *testing.T) {
ctx := acctest.Context(t)
var v types.LogGroup
Expand Down Expand Up @@ -460,6 +484,15 @@ resource "aws_cloudwatch_log_group" "test" {
`, rName, idx)
}

func testAccGroupConfig_logGroupClass(rName string, val string) string {
return fmt.Sprintf(`
resource "aws_cloudwatch_log_group" "test" {
name = %[1]q
log_group_class = %[2]q
}
`, rName, val)
}

func testAccGroupConfig_retentionPolicy(rName string, val int) string {
return fmt.Sprintf(`
resource "aws_cloudwatch_log_group" "test" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/cloudwatch_log_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ This resource supports the following arguments:
* `name` - (Optional, Forces new resource) The name of the log group. If omitted, Terraform will assign a random, unique name.
* `name_prefix` - (Optional, Forces new resource) Creates a unique name beginning with the specified prefix. Conflicts with `name`.
* `skip_destroy` - (Optional) Set to true if you do not wish the log group (and any logs it may contain) to be deleted at destroy time, and instead just remove the log group from the Terraform state.
* `log_group_class` - (Optional) Specified the log class of the log group. Possible values are: `STANDARD` or `INFREQUENT_ACCESS`.
* `retention_in_days` - (Optional) Specifies the number of days
you want to retain log events in the specified log group. Possible values are: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1096, 1827, 2192, 2557, 2922, 3288, 3653, and 0.
If you select 0, the events in the log group are always retained and never expire.
Expand Down

0 comments on commit 8c993e5

Please sign in to comment.