/
backup_vault.go
76 lines (64 loc) · 2.04 KB
/
backup_vault.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package resources
import (
"context"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/backup"
"github.com/gruntwork-io/cloud-nuke/config"
"github.com/gruntwork-io/cloud-nuke/logging"
"github.com/gruntwork-io/cloud-nuke/report"
"github.com/gruntwork-io/cloud-nuke/telemetry"
"github.com/gruntwork-io/go-commons/errors"
commonTelemetry "github.com/gruntwork-io/go-commons/telemetry"
)
func (bv *BackupVault) getAll(c context.Context, configObj config.Config) ([]*string, error) {
names := []*string{}
paginator := func(output *backup.ListBackupVaultsOutput, lastPage bool) bool {
for _, backupVault := range output.BackupVaultList {
if configObj.BackupVault.ShouldInclude(config.ResourceValue{
Name: backupVault.BackupVaultName,
Time: backupVault.CreationDate,
}) {
names = append(names, backupVault.BackupVaultName)
}
}
return !lastPage
}
err := bv.Client.ListBackupVaultsPages(&backup.ListBackupVaultsInput{}, paginator)
if err != nil {
return nil, errors.WithStackTrace(err)
}
return names, nil
}
func (bv *BackupVault) nukeAll(names []*string) error {
if len(names) == 0 {
logging.Debugf("No backup vaults to nuke in region %s", bv.Region)
return nil
}
logging.Debugf("Deleting all backup vaults in region %s", bv.Region)
var deletedNames []*string
for _, name := range names {
_, err := bv.Client.DeleteBackupVault(&backup.DeleteBackupVaultInput{
BackupVaultName: name,
})
// Record status of this resource
e := report.Entry{
Identifier: aws.StringValue(name),
ResourceType: "Backup Vault",
Error: err,
}
report.Record(e)
if err != nil {
logging.Debugf("[Failed] %s", err)
telemetry.TrackEvent(commonTelemetry.EventContext{
EventName: "Error Nuking BackupVault",
}, map[string]interface{}{
"region": bv.Region,
})
} else {
deletedNames = append(deletedNames, name)
logging.Debugf("Deleted backup vault: %s", aws.StringValue(name))
}
}
logging.Debugf("[OK] %d backup vault deleted in %s", len(deletedNames), bv.Region)
return nil
}