2021-07-07 15:08:17 +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 RDSDBInstanceEnumerator struct {
|
|
|
|
repository repository.RDSRepository
|
|
|
|
factory resource.ResourceFactory
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRDSDBInstanceEnumerator(repo repository.RDSRepository, factory resource.ResourceFactory) *RDSDBInstanceEnumerator {
|
|
|
|
return &RDSDBInstanceEnumerator{
|
|
|
|
repository: repo,
|
|
|
|
factory: factory,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *RDSDBInstanceEnumerator) SupportedType() resource.ResourceType {
|
|
|
|
return aws.AwsDbInstanceResourceType
|
|
|
|
}
|
|
|
|
|
2021-08-09 14:03:04 +00:00
|
|
|
func (e *RDSDBInstanceEnumerator) Enumerate() ([]*resource.Resource, error) {
|
2021-07-07 15:08:17 +00:00
|
|
|
instances, err := e.repository.ListAllDBInstances()
|
|
|
|
if err != nil {
|
2021-08-03 10:34:36 +00:00
|
|
|
return nil, remoteerror.NewResourceListingError(err, string(e.SupportedType()))
|
2021-07-07 15:08:17 +00:00
|
|
|
}
|
|
|
|
|
2021-08-09 14:03:04 +00:00
|
|
|
results := make([]*resource.Resource, len(instances))
|
2021-07-07 15:08:17 +00:00
|
|
|
|
|
|
|
for _, instance := range instances {
|
|
|
|
results = append(
|
|
|
|
results,
|
|
|
|
e.factory.CreateAbstractResource(
|
|
|
|
string(e.SupportedType()),
|
|
|
|
*instance.DBInstanceIdentifier,
|
|
|
|
map[string]interface{}{},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return results, err
|
|
|
|
}
|