2020-12-09 15:31:34 +00:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
2021-02-24 16:29:57 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/remote/aws/repository"
|
2021-01-20 13:01:57 +00:00
|
|
|
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
|
2020-12-09 15:31:34 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/resource"
|
|
|
|
resourceaws "github.com/cloudskiff/driftctl/pkg/resource/aws"
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/terraform"
|
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DBInstanceSupplier struct {
|
|
|
|
reader terraform.ResourceReader
|
2021-05-21 14:09:45 +00:00
|
|
|
deserializer *resource.Deserializer
|
2021-02-24 16:29:57 +00:00
|
|
|
client repository.RDSRepository
|
2020-12-09 15:31:34 +00:00
|
|
|
runner *terraform.ParallelResourceReader
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:09:45 +00:00
|
|
|
func NewDBInstanceSupplier(provider *AWSTerraformProvider, deserializer *resource.Deserializer) *DBInstanceSupplier {
|
2021-01-20 13:01:57 +00:00
|
|
|
return &DBInstanceSupplier{
|
2021-01-22 17:06:17 +00:00
|
|
|
provider,
|
2021-05-21 14:09:45 +00:00
|
|
|
deserializer,
|
2021-02-24 16:29:57 +00:00
|
|
|
repository.NewRDSRepository(provider.session),
|
2021-01-22 17:06:17 +00:00
|
|
|
terraform.NewParallelResourceReader(provider.Runner().SubRunner()),
|
2021-01-20 13:01:57 +00:00
|
|
|
}
|
2020-12-09 15:31:34 +00:00
|
|
|
}
|
|
|
|
|
2021-03-17 15:54:53 +00:00
|
|
|
func (s *DBInstanceSupplier) Resources() ([]resource.Resource, error) {
|
2020-12-09 15:31:34 +00:00
|
|
|
|
2021-02-24 16:29:57 +00:00
|
|
|
resourceList, err := s.client.ListAllDBInstances()
|
2020-12-09 15:31:34 +00:00
|
|
|
|
|
|
|
if err != nil {
|
2021-01-20 13:01:57 +00:00
|
|
|
return nil, remoteerror.NewResourceEnumerationError(err, resourceaws.AwsDbInstanceResourceType)
|
2020-12-09 15:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, res := range resourceList {
|
|
|
|
id := *res.DBInstanceIdentifier
|
|
|
|
s.runner.Run(func() (cty.Value, error) {
|
|
|
|
completeResource, err := s.reader.ReadResource(terraform.ReadResourceArgs{
|
|
|
|
Ty: resourceaws.AwsDbInstanceResourceType,
|
|
|
|
ID: id,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
logrus.Warnf("Error reading %s[%s]: %+v", id, resourceaws.AwsDbInstanceResourceType, err)
|
|
|
|
return cty.NilVal, err
|
|
|
|
}
|
|
|
|
return *completeResource, nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
results, err := s.runner.Wait()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:09:45 +00:00
|
|
|
return s.deserializer.Deserialize(resourceaws.AwsDbInstanceResourceType, results)
|
2020-12-09 15:31:34 +00:00
|
|
|
}
|