@@ -10,6 +10,7 @@ import (
10
10
type CloudWatchAlarm struct {
11
11
svc * cloudwatch.CloudWatch
12
12
alarmName * string
13
+ tags []* cloudwatch.Tag
13
14
}
14
15
15
16
func init () {
@@ -31,9 +32,14 @@ func ListCloudWatchAlarms(sess *session.Session) ([]Resource, error) {
31
32
}
32
33
33
34
for _ , metricAlarm := range output .MetricAlarms {
35
+ tags , err := GetAlarmTags (svc , metricAlarm .AlarmArn )
36
+ if err != nil {
37
+ return nil , err
38
+ }
34
39
resources = append (resources , & CloudWatchAlarm {
35
40
svc : svc ,
36
41
alarmName : metricAlarm .AlarmName ,
42
+ tags : tags ,
37
43
})
38
44
}
39
45
@@ -47,6 +53,15 @@ func ListCloudWatchAlarms(sess *session.Session) ([]Resource, error) {
47
53
return resources , nil
48
54
}
49
55
56
+ func GetAlarmTags (svc * cloudwatch.CloudWatch , arn * string ) ([]* cloudwatch.Tag , error ) {
57
+ resp , err := svc .ListTagsForResource (& cloudwatch.ListTagsForResourceInput {ResourceARN : arn })
58
+ if err != nil {
59
+ return nil , err
60
+ }
61
+
62
+ return resp .Tags , nil
63
+ }
64
+
50
65
func (f * CloudWatchAlarm ) Remove () error {
51
66
52
67
_ , err := f .svc .DeleteAlarms (& cloudwatch.DeleteAlarmsInput {
@@ -57,8 +72,13 @@ func (f *CloudWatchAlarm) Remove() error {
57
72
}
58
73
59
74
func (f * CloudWatchAlarm ) Properties () types.Properties {
60
- return types .NewProperties ().
61
- Set ("Name" , f .alarmName )
75
+ properties := types .NewProperties ()
76
+ properties .Set ("Name" , f .alarmName )
77
+
78
+ for _ , tag := range f .tags {
79
+ properties .SetTag (tag .Key , tag .Value )
80
+ }
81
+ return properties
62
82
}
63
83
64
84
func (f * CloudWatchAlarm ) String () string {
0 commit comments