/
cloudwatch_alarm_types.go
57 lines (46 loc) · 1.43 KB
/
cloudwatch_alarm_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package resources
import (
"context"
awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface"
"github.com/gruntwork-io/cloud-nuke/config"
"github.com/gruntwork-io/go-commons/errors"
)
// CloudWatchAlarms - represents all CloudWatchAlarms that should be deleted.
type CloudWatchAlarms struct {
BaseAwsResource
Client cloudwatchiface.CloudWatchAPI
Region string
AlarmNames []string
}
func (cw *CloudWatchAlarms) Init(session *session.Session) {
cw.Client = cloudwatch.New(session)
}
// ResourceName - the simple name of the aws resource
func (cw *CloudWatchAlarms) ResourceName() string {
return "cloudwatch-alarm"
}
// ResourceIdentifiers - The name of cloudwatch alarms
func (cw *CloudWatchAlarms) ResourceIdentifiers() []string {
return cw.AlarmNames
}
func (cw *CloudWatchAlarms) MaxBatchSize() int {
return 99
}
func (cw *CloudWatchAlarms) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) {
identifiers, err := cw.getAll(c, configObj)
if err != nil {
return nil, err
}
cw.AlarmNames = awsgo.StringValueSlice(identifiers)
return cw.AlarmNames, nil
}
// Nuke - nuke 'em all!!!
func (cw *CloudWatchAlarms) Nuke(identifiers []string) error {
if err := cw.nukeAll(awsgo.StringSlice(identifiers)); err != nil {
return errors.WithStackTrace(err)
}
return nil
}