-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Added cloudwatch log group data source #4167
Added cloudwatch log group data source #4167
Conversation
Derp forgot to add docs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @sjauld thanks for this contribution. Left some initial comments below. Please let me know if you have any questions!
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field should be Required
to match the documentation and desired behavior 😉
} | ||
|
||
func dataSourceAwsCloudwatchLogGroupRead(d *schema.ResourceData, meta interface{}) error { | ||
name := aws.String(d.Get("name").(string)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick: usually its easier to work with the name := d.Get("name").(string)
and only wrap it with aws.String(name)
when creating the AWS SDK structs so you don't need to dereference the pointer every time. 👍
var logGroup *cloudwatchlogs.LogGroup | ||
|
||
for _, lg := range resp.LogGroups { | ||
if *lg.LogGroupName == *name { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To prevent potential crashes, we should wrap this with aws.StringValue(lg.LogGroupName)
in the unlikely chance that it comes back as nil
LogGroupNamePrefix: name, | ||
} | ||
|
||
resp, err := conn.DescribeLogGroups(input) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use the SDK provided paginator to handle cases where over 50 results are returned: https://docs.aws.amazon.com/sdk-for-go/api/service/cloudwatchlogs/#CloudWatchLogs.DescribeLogGroupsPages
Thanks for the feedback @bflad! |
Tests rerun.
|
|
||
var testAccCheckAWSCloudwatchLogGroupDataSourceConfig = fmt.Sprintf(` | ||
resource aws_cloudwatch_log_group "test" { | ||
name = "Test" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should randomize the naming here in case of AWS/testing failures 😄 I will fix this during merge to be %s
, make testAccCheckAWSCloudwatchLogGroupDataSourceConfig
a function with rName string
parameter, and generate the random name via something like rName := acctest.RandomWithPrefix("tf-acc-test")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome job, LGTM! 🚀
make testacc TEST=./aws TESTARGS='-run=TestAccAWSCloudwatchLogGroupDataSource'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSCloudwatchLogGroupDataSource -timeout 120m
=== RUN TestAccAWSCloudwatchLogGroupDataSource
--- PASS: TestAccAWSCloudwatchLogGroupDataSource (14.64s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 14.679s
This has been released in version 1.15.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Ref #3247