2021-07-05 10:31:11 +00:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
|
|
|
"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 EC2RouteTableEnumerator struct {
|
|
|
|
repository repository.EC2Repository
|
|
|
|
factory resource.ResourceFactory
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewEC2RouteTableEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory) *EC2RouteTableEnumerator {
|
|
|
|
return &EC2RouteTableEnumerator{
|
|
|
|
repository: repo,
|
|
|
|
factory: factory,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *EC2RouteTableEnumerator) SupportedType() resource.ResourceType {
|
|
|
|
return aws.AwsRouteTableResourceType
|
|
|
|
}
|
|
|
|
|
2021-08-09 14:03:04 +00:00
|
|
|
func (e *EC2RouteTableEnumerator) Enumerate() ([]*resource.Resource, error) {
|
2021-07-05 10:31:11 +00:00
|
|
|
routeTables, err := e.repository.ListAllRouteTables()
|
|
|
|
if err != nil {
|
2021-08-03 10:34:36 +00:00
|
|
|
return nil, remoteerror.NewResourceListingError(err, string(e.SupportedType()))
|
2021-07-05 10:31:11 +00:00
|
|
|
}
|
|
|
|
|
2021-08-09 14:03:04 +00:00
|
|
|
var results []*resource.Resource
|
2021-07-05 10:31:11 +00:00
|
|
|
|
|
|
|
for _, routeTable := range routeTables {
|
|
|
|
if !isMainRouteTable(routeTable) {
|
|
|
|
results = append(
|
|
|
|
results,
|
|
|
|
e.factory.CreateAbstractResource(
|
|
|
|
string(e.SupportedType()),
|
|
|
|
*routeTable.RouteTableId,
|
|
|
|
map[string]interface{}{},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return results, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func isMainRouteTable(routeTable *ec2.RouteTable) bool {
|
|
|
|
for _, assoc := range routeTable.Associations {
|
|
|
|
if assoc.Main != nil && *assoc.Main {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|