-
-
Notifications
You must be signed in to change notification settings - Fork 354
/
ec2_internet_gateway_types.go
60 lines (48 loc) · 1.58 KB
/
ec2_internet_gateway_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
58
59
60
package resources
import (
"context"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
"github.com/gruntwork-io/cloud-nuke/config"
"github.com/gruntwork-io/go-commons/errors"
)
type InternetGateway struct {
BaseAwsResource
Client ec2iface.EC2API
Region string
GatewayIds []string
GatewayVPCMap map[string]string
}
func (igw *InternetGateway) Init(session *session.Session) {
igw.BaseAwsResource.Init(session)
igw.Client = ec2.New(session)
// Since the nuking of the internet gateway requires the VPC ID, and to avoid redundant API calls for this information within the nuke method,
// we utilize the getAll method to retrieve it.
// This map is used to store the information and access the value within the nuke method.
igw.GatewayVPCMap = make(map[string]string)
}
func (igw *InternetGateway) ResourceName() string {
return "internet-gateway"
}
func (igw *InternetGateway) ResourceIdentifiers() []string {
return igw.GatewayIds
}
func (igw *InternetGateway) MaxBatchSize() int {
return 50
}
func (igw *InternetGateway) GetAndSetIdentifiers(c context.Context, configObj config.Config) ([]string, error) {
identifiers, err := igw.getAll(c, configObj)
if err != nil {
return nil, err
}
igw.GatewayIds = aws.StringValueSlice(identifiers)
return igw.GatewayIds, nil
}
func (igw *InternetGateway) Nuke(identifiers []string) error {
if err := igw.nukeAll(aws.StringSlice(identifiers)); err != nil {
return errors.WithStackTrace(err)
}
return nil
}