/
ec2_natgateway.go
executable file
·50 lines (44 loc) · 1.26 KB
/
ec2_natgateway.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
package lister
import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/trek10inc/awsets/context"
"github.com/trek10inc/awsets/resource"
)
type AWSEc2NatGateway struct {
}
func init() {
i := AWSEc2NatGateway{}
listers = append(listers, i)
}
func (l AWSEc2NatGateway) Types() []resource.ResourceType {
return []resource.ResourceType{resource.Ec2NatGateway}
}
func (l AWSEc2NatGateway) List(ctx context.AWSetsCtx) (*resource.Group, error) {
svc := ec2.NewFromConfig(ctx.AWSCfg)
rg := resource.NewGroup()
err := Paginator(func(nt *string) (*string, error) {
res, err := svc.DescribeNatGateways(ctx.Context, &ec2.DescribeNatGatewaysInput{
MaxResults: aws.Int32(1000),
NextToken: nt,
})
if err != nil {
return nil, err
}
for _, v := range res.NatGateways {
r := resource.New(ctx, resource.Ec2NatGateway, v.NatGatewayId, v.NatGatewayId, v)
if v.SubnetId != nil {
r.AddRelation(resource.Ec2Subnet, v.SubnetId, "")
}
if v.VpcId != nil {
r.AddRelation(resource.Ec2Vpc, v.VpcId, "")
}
for _, gwAddress := range v.NatGatewayAddresses {
r.AddRelation(resource.Ec2NetworkInterface, gwAddress.NetworkInterfaceId, "")
}
rg.AddResource(r)
}
return res.NextToken, nil
})
return rg, err
}