generated from patmizi/go-cli-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chaos_rollback.go
41 lines (35 loc) · 1.35 KB
/
chaos_rollback.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
package chaosutil
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/golang/glog"
. "github.com/patmizi/aws-chaos-cli/lib/types"
"github.com/pkg/errors"
)
func Rollback(ec2Client *ec2.EC2, rollbackData []NaclAssociationPair, asClient *autoscaling.AutoScaling, originalAsg *autoscaling.Group) error {
glog.Info("Rolling back Network ACL to original configuration")
for _, nacl := range rollbackData {
_, err := ec2Client.ReplaceNetworkAclAssociation(&ec2.ReplaceNetworkAclAssociationInput{
AssociationId: aws.String(nacl.NaclAssociationId),
NetworkAclId: aws.String(nacl.NaclId),
})
if err != nil {
glog.Error("(Skipping) Could not replace network acl association\n")
} else {
glog.Infof("Rolled back\n")
}
}
if originalAsg != nil {
glog.Info("Rolling back AutoScalingGroup to original configuration\n")
_, err := asClient.UpdateAutoScalingGroup(&autoscaling.UpdateAutoScalingGroupInput{
AutoScalingGroupName: originalAsg.AutoScalingGroupName,
VPCZoneIdentifier: originalAsg.VPCZoneIdentifier,
})
if err != nil {
return errors.Wrap(err, "Could not update autoscaling group")
}
glog.Info("Reverted back autoscaling group changes\n")
}
return nil
}