-
-
Notifications
You must be signed in to change notification settings - Fork 358
/
route53_hostedzone.go
64 lines (53 loc) · 1.6 KB
/
route53_hostedzone.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
package resources
import (
"context"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/gruntwork-io/cloud-nuke/config"
"github.com/gruntwork-io/cloud-nuke/logging"
"github.com/gruntwork-io/cloud-nuke/report"
)
func (r *Route53HostedZone) getAll(c context.Context, configObj config.Config) ([]*string, error) {
var ids []*string
result, err := r.Client.ListHostedZones(&route53.ListHostedZonesInput{})
if err != nil {
logging.Errorf("[Failed] unable to list hosted-zones: %s", err)
return nil, err
}
for _, r := range result.HostedZones {
if configObj.Route53HostedZone.ShouldInclude(config.ResourceValue{
Name: r.Name,
}) {
ids = append(ids, r.Id)
}
}
return ids, nil
}
func (r *Route53HostedZone) nukeAll(identifiers []*string) (err error) {
if len(identifiers) == 0 {
logging.Debugf("No Route53 Hosted Zones to nuke in region %s", r.Region)
return nil
}
logging.Debugf("Deleting all Route53 Hosted Zones in region %s", r.Region)
var deletedIds []*string
for _, id := range identifiers {
_, err := r.Client.DeleteHostedZone(&route53.DeleteHostedZoneInput{
Id: id,
})
// Record status of this resource
e := report.Entry{
Identifier: aws.StringValue(id),
ResourceType: "Route53 hosted zone",
Error: err,
}
report.Record(e)
if err != nil {
logging.Errorf("[Failed] %s: %s", *id, err)
} else {
deletedIds = append(deletedIds, id)
logging.Debugf("Deleted Route53 Hosted Zone: %s", aws.StringValue(id))
}
}
logging.Debugf("[OK] %d Route53 hosted zone(s) deleted in %s", len(deletedIds), r.Region)
return nil
}