2021-06-30 15:30:12 +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/aws"
|
|
|
|
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/resource"
|
|
|
|
)
|
|
|
|
|
|
|
|
type VPCEnumerator struct {
|
|
|
|
repo repository.EC2Repository
|
|
|
|
factory resource.ResourceFactory
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewVPCEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory) *VPCEnumerator {
|
|
|
|
return &VPCEnumerator{
|
|
|
|
repo,
|
|
|
|
factory,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *VPCEnumerator) SupportedType() resource.ResourceType {
|
|
|
|
return aws.AwsVpcResourceType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *VPCEnumerator) Enumerate() ([]resource.Resource, error) {
|
2021-06-30 16:00:38 +00:00
|
|
|
VPCs, _, err := e.repo.ListAllVPCs()
|
2021-06-30 15:30:12 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, remoteerror.NewResourceEnumerationError(err, aws.AwsVpcResourceType)
|
|
|
|
}
|
|
|
|
|
2021-06-30 16:00:38 +00:00
|
|
|
results := make([]resource.Resource, 0, len(VPCs))
|
2021-06-30 15:30:12 +00:00
|
|
|
|
|
|
|
for _, item := range VPCs {
|
|
|
|
results = append(
|
|
|
|
results,
|
2021-06-30 16:00:38 +00:00
|
|
|
e.factory.CreateAbstractResource(
|
|
|
|
string(e.SupportedType()),
|
|
|
|
*item.VpcId,
|
|
|
|
map[string]interface{}{},
|
|
|
|
),
|
2021-06-30 15:30:12 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return results, nil
|
|
|
|
}
|