driftctl/enumeration/remote/aws/default_vpc_enumerator.go

48 lines
1.1 KiB
Go
Raw Normal View History

2021-06-30 16:00:38 +00:00
package aws
import (
"github.com/snyk/driftctl/enumeration/remote/aws/repository"
remoteerror "github.com/snyk/driftctl/enumeration/remote/error"
"github.com/snyk/driftctl/enumeration/resource/aws"
2021-06-30 16:00:38 +00:00
"github.com/snyk/driftctl/enumeration/resource"
2021-06-30 16:00:38 +00:00
)
type DefaultVPCEnumerator struct {
repo repository.EC2Repository
factory resource.ResourceFactory
}
func NewDefaultVPCEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory) *DefaultVPCEnumerator {
return &DefaultVPCEnumerator{
repo,
factory,
}
}
func (e *DefaultVPCEnumerator) SupportedType() resource.ResourceType {
return aws.AwsDefaultVpcResourceType
}
2021-08-09 14:03:04 +00:00
func (e *DefaultVPCEnumerator) Enumerate() ([]*resource.Resource, error) {
2021-06-30 16:00:38 +00:00
_, defaultVPCs, err := e.repo.ListAllVPCs()
if err != nil {
2021-08-04 09:08:08 +00:00
return nil, remoteerror.NewResourceListingError(err, string(e.SupportedType()))
2021-06-30 16:00:38 +00:00
}
2021-08-09 14:03:04 +00:00
results := make([]*resource.Resource, 0, len(defaultVPCs))
2021-06-30 16:00:38 +00:00
for _, item := range defaultVPCs {
results = append(
results,
e.factory.CreateAbstractResource(
string(e.SupportedType()),
*item.VpcId,
map[string]interface{}{},
),
)
}
return results, nil
}