This repository was archived by the owner on Oct 15, 2024. It is now read-only.
File tree 2 files changed +61
-1
lines changed
2 files changed +61
-1
lines changed Original file line number Diff line number Diff line change
1
+ package resources
2
+
3
+ import (
4
+ "fmt"
5
+
6
+ "github.com/aws/aws-sdk-go/aws"
7
+ "github.com/aws/aws-sdk-go/service/ec2"
8
+ )
9
+
10
+ type EC2SpotFleetRequest struct {
11
+ svc * ec2.EC2
12
+ id string
13
+ state string
14
+ }
15
+
16
+ func (n * EC2Nuke ) ListSpotFleetRequests () ([]Resource , error ) {
17
+ resp , err := n .Service .DescribeSpotFleetRequests (nil )
18
+ if err != nil {
19
+ return nil , err
20
+ }
21
+
22
+ resources := make ([]Resource , 0 )
23
+ for _ , config := range resp .SpotFleetRequestConfigs {
24
+ resources = append (resources , & EC2SpotFleetRequest {
25
+ svc : n .Service ,
26
+ id : * config .SpotFleetRequestId ,
27
+ state : * config .SpotFleetRequestState ,
28
+ })
29
+ }
30
+
31
+ return resources , nil
32
+ }
33
+
34
+ func (i * EC2SpotFleetRequest ) Filter () error {
35
+ if i .state == "cancelled" {
36
+ return fmt .Errorf ("already cancelled" )
37
+ }
38
+ return nil
39
+ }
40
+
41
+ func (i * EC2SpotFleetRequest ) Remove () error {
42
+ params := & ec2.CancelSpotFleetRequestsInput {
43
+ TerminateInstances : aws .Bool (true ),
44
+ SpotFleetRequestIds : []* string {
45
+ & i .id ,
46
+ },
47
+ }
48
+
49
+ _ , err := i .svc .CancelSpotFleetRequests (params )
50
+ if err != nil {
51
+ return err
52
+ }
53
+
54
+ return nil
55
+ }
56
+
57
+ func (i * EC2SpotFleetRequest ) String () string {
58
+ return i .id
59
+ }
Original file line number Diff line number Diff line change @@ -58,10 +58,11 @@ func GetListers(sess *session.Session) []ResourceLister {
58
58
ec2 .ListNetworkACLs ,
59
59
ec2 .ListRouteTables ,
60
60
ec2 .ListSecurityGroups ,
61
+ ec2 .ListSpotFleetRequests ,
61
62
ec2 .ListSubnets ,
62
63
ec2 .ListVolumes ,
63
- ec2 .ListVpcs ,
64
64
ec2 .ListVpcEndpoints ,
65
+ ec2 .ListVpcs ,
65
66
ec2 .ListVpnConnections ,
66
67
ec2 .ListVpnGatewayAttachements ,
67
68
ec2 .ListVpnGateways ,
You can’t perform that action at this time.
0 commit comments