Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d/cloudwatch_logs_groups - make log_group_name_prefix optional #25187

Merged
merged 2 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/25187.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
data-source/aws_cloudwatch_logs_groups: Make `log_group_name_prefix` optional
```
8 changes: 5 additions & 3 deletions internal/service/logs/groups_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func DataSourceGroups() *schema.Resource {
},
"log_group_name_prefix": {
Type: schema.TypeString,
Required: true,
Optional: true,
},
"log_group_names": {
Type: schema.TypeSet,
Expand All @@ -35,8 +35,10 @@ func DataSourceGroups() *schema.Resource {
func dataSourceGroupsRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).LogsConn

input := &cloudwatchlogs.DescribeLogGroupsInput{
LogGroupNamePrefix: aws.String(d.Get("log_group_name_prefix").(string)),
input := &cloudwatchlogs.DescribeLogGroupsInput{}

if v, ok := d.GetOk("log_group_name_prefix"); ok {
input.LogGroupNamePrefix = aws.String(v.(string))
}

var results []*cloudwatchlogs.LogGroup
Expand Down
38 changes: 38 additions & 0 deletions internal/service/logs/groups_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ func TestAccLogsGroupsDataSource_basic(t *testing.T) {
})
}

func TestAccLogsGroupsDataSource_noPrefix(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "data.aws_cloudwatch_log_groups.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, cloudwatchlogs.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccGroupsDataSourceConfig_noPrefix(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckTypeSetElemAttrPair(resourceName, "arns.*", "aws_cloudwatch_log_group.test1", "arn"),
resource.TestCheckTypeSetElemAttrPair(resourceName, "arns.*", "aws_cloudwatch_log_group.test2", "arn"),
resource.TestCheckTypeSetElemAttrPair(resourceName, "log_group_names.*", "aws_cloudwatch_log_group.test1", "name"),
resource.TestCheckTypeSetElemAttrPair(resourceName, "log_group_names.*", "aws_cloudwatch_log_group.test2", "name"),
),
},
},
})
}

func testAccGroupsDataSourceConfig_basic(rName string) string {
return fmt.Sprintf(`
resource aws_cloudwatch_log_group "test1" {
Expand All @@ -51,3 +73,19 @@ data aws_cloudwatch_log_groups "test" {
}
`, rName)
}

func testAccGroupsDataSourceConfig_noPrefix(rName string) string {
return fmt.Sprintf(`
resource aws_cloudwatch_log_group "test1" {
name = "%[1]s/1"
}

resource aws_cloudwatch_log_group "test2" {
name = "%[1]s/2"
}

data aws_cloudwatch_log_groups "test" {
depends_on = [aws_cloudwatch_log_group.test1,aws_cloudwatch_log_group.test2]
}
`, rName)
}
2 changes: 1 addition & 1 deletion website/docs/d/cloudwatch_log_groups.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ data "aws_cloudwatch_log_groups" "example" {

The following arguments are supported:

* `log_group_name_prefix` - (Required) The group prefix of the Cloudwatch log groups to list
* `log_group_name_prefix` - (Optional) The group prefix of the Cloudwatch log groups to list

## Attributes Reference

Expand Down