Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Add tag filtering for cloudwatch alarms #900

Merged
Merged
Changes from 2 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
16 changes: 14 additions & 2 deletions resources/cloudwatch-alarms.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
type CloudWatchAlarm struct {
svc *cloudwatch.CloudWatch
alarmName *string
tags []*cloudwatch.Tag
}

func init() {
Expand All @@ -34,6 +35,7 @@ func ListCloudWatchAlarms(sess *session.Session) ([]Resource, error) {
resources = append(resources, &CloudWatchAlarm{
svc: svc,
alarmName: metricAlarm.AlarmName,
tags: GetAlarmTags(svc, metricAlarm.AlarmArn),
})
}

Expand All @@ -47,6 +49,11 @@ func ListCloudWatchAlarms(sess *session.Session) ([]Resource, error) {
return resources, nil
}

func GetAlarmTags(svc *cloudwatch.CloudWatch, arn *string) []*cloudwatch.Tag {
resp, _ := svc.ListTagsForResource(&cloudwatch.ListTagsForResourceInput{ResourceARN: arn})
return resp.Tags
}

func (f *CloudWatchAlarm) Remove() error {

_, err := f.svc.DeleteAlarms(&cloudwatch.DeleteAlarmsInput{
Expand All @@ -57,8 +64,13 @@ func (f *CloudWatchAlarm) Remove() error {
}

func (f *CloudWatchAlarm) Properties() types.Properties {
return types.NewProperties().
Set("Name", f.alarmName)
properties := types.NewProperties()
properties.Set("Name", f.alarmName)

for _, tag := range f.tags {
properties.SetTag(tag.Key, tag.Value)
}
return properties
}

func (f *CloudWatchAlarm) String() string {
Expand Down