2021-07-06 14:24:54 +00:00
|
|
|
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 {
|
2021-08-03 10:34:36 +00:00
|
|
|
return nil, remoteerror.NewResourceListingError(err, string(e.SupportedType()))
|
2021-07-06 14:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
results := make([]resource.Resource, len(natGateways))
|
|
|
|
|
|
|
|
for _, natGateway := range natGateways {
|
2021-07-20 15:51:51 +00:00
|
|
|
|
|
|
|
attrs := map[string]interface{}{}
|
|
|
|
if len(natGateway.NatGatewayAddresses) > 0 {
|
|
|
|
if allocId := natGateway.NatGatewayAddresses[0].AllocationId; allocId != nil {
|
|
|
|
attrs["allocation_id"] = *allocId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-06 14:24:54 +00:00
|
|
|
results = append(
|
|
|
|
results,
|
|
|
|
e.factory.CreateAbstractResource(
|
|
|
|
string(e.SupportedType()),
|
|
|
|
*natGateway.NatGatewayId,
|
2021-07-20 15:51:51 +00:00
|
|
|
attrs,
|
2021-07-06 14:24:54 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return results, err
|
|
|
|
}
|