Skip to content

Commit 52103ce

Browse files
committed
✨ Add Cloudwatch log group tags to resource.
Signed-off-by: Vasil Sirakov <sirakov97@gmail.com>
1 parent d6addbb commit 52103ce

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

providers/aws/resources/aws.lr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,6 +1767,8 @@ private aws.cloudwatch.loggroup @defaults("arn") {
17671767
region string
17681768
// Number of days to retain the log events in the specified log group
17691769
retentionInDays int
1770+
// Tags for the log group
1771+
tags map[string]string
17701772
}
17711773

17721774
// Amazon CloudWatch log group metrics filter

providers/aws/resources/aws.lr.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

providers/aws/resources/aws.lr.manifest.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,8 @@ resources:
539539
region: {}
540540
retentionInDays:
541541
min_mondoo_version: 9.0.0
542+
tags:
543+
min_mondoo_version: 9.0.0
542544
is_private: true
543545
min_mondoo_version: 5.15.0
544546
platform:

providers/aws/resources/aws_cloudwatch.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"crypto/sha256"
99
"encoding/json"
1010
"fmt"
11+
"maps"
1112
"strings"
1213
"time"
1314

@@ -585,14 +586,25 @@ func (a *mqlAwsCloudwatch) getLogGroups(conn *connection.AwsConnection) []*jobpo
585586
}
586587
args := make(map[string]*llx.RawData)
587588
for _, loggroup := range logGroups.LogGroups {
589+
tags := make(map[string]any)
590+
groupTags, err := svc.ListTagsForResource(ctx, &cloudwatchlogs.ListTagsForResourceInput{
591+
ResourceArn: loggroup.LogGroupArn,
592+
})
593+
if err == nil {
594+
maps.Copy(tags, strMapToInterface(groupTags.Tags))
595+
} else {
596+
log.Warn().Msgf("could not get tags for log group %s: %v", convert.ToValue(loggroup.LogGroupName), err)
597+
}
598+
588599
args["arn"] = llx.StringDataPtr(loggroup.Arn)
589600
args["name"] = llx.StringDataPtr(loggroup.LogGroupName)
590601
args["region"] = llx.StringData(region)
591602
args["retentionInDays"] = llx.IntDataDefault(loggroup.RetentionInDays, 0)
603+
args["tags"] = llx.MapData(tags, types.String)
592604

593605
// add kms key if there is one
594606
if loggroup.KmsKeyId != nil {
595-
mqlKeyResource, err := NewResource(a.MqlRuntime, "aws.kms.key",
607+
mqlKeyResource, err := NewResource(a.MqlRuntime, ResourceAwsKmsKey,
596608
map[string]*llx.RawData{
597609
"arn": llx.StringDataPtr(loggroup.KmsKeyId),
598610
})
@@ -606,7 +618,7 @@ func (a *mqlAwsCloudwatch) getLogGroups(conn *connection.AwsConnection) []*jobpo
606618
args["kmsKey"] = llx.NilData
607619
}
608620

609-
mqlLogGroup, err := CreateResource(a.MqlRuntime, "aws.cloudwatch.loggroup", args)
621+
mqlLogGroup, err := CreateResource(a.MqlRuntime, ResourceAwsCloudwatchLoggroup, args)
610622
if err != nil {
611623
return nil, err
612624
}

0 commit comments

Comments
 (0)