/
ec2_nat_gateway_enumerator.go
54 lines (44 loc) · 1.38 KB
/
ec2_nat_gateway_enumerator.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
package aws
import (
"github.com/cloudskiff/driftctl/pkg/remote/aws/repository"
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
"github.com/cloudskiff/driftctl/pkg/resource"
"github.com/cloudskiff/driftctl/pkg/resource/aws"
)
type EC2NatGatewayEnumerator struct {
repository repository.EC2Repository
factory resource.ResourceFactory
}
func NewEC2NatGatewayEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory) *EC2NatGatewayEnumerator {
return &EC2NatGatewayEnumerator{
repository: repo,
factory: factory,
}
}
func (e *EC2NatGatewayEnumerator) SupportedType() resource.ResourceType {
return aws.AwsNatGatewayResourceType
}
func (e *EC2NatGatewayEnumerator) Enumerate() ([]*resource.Resource, error) {
natGateways, err := e.repository.ListAllNatGateways()
if err != nil {
return nil, remoteerror.NewResourceListingError(err, string(e.SupportedType()))
}
results := make([]*resource.Resource, 0, len(natGateways))
for _, natGateway := range natGateways {
attrs := map[string]interface{}{}
if len(natGateway.NatGatewayAddresses) > 0 {
if allocId := natGateway.NatGatewayAddresses[0].AllocationId; allocId != nil {
attrs["allocation_id"] = *allocId
}
}
results = append(
results,
e.factory.CreateAbstractResource(
string(e.SupportedType()),
*natGateway.NatGatewayId,
attrs,
),
)
}
return results, err
}