2021-02-11 11:21:49 +00:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/remote/aws/repository"
|
|
|
|
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/remote/deserializer"
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/resource"
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/resource/aws"
|
|
|
|
awsdeserializer "github.com/cloudskiff/driftctl/pkg/resource/aws/deserializer"
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DynamoDBTableSupplier struct {
|
|
|
|
reader terraform.ResourceReader
|
|
|
|
deserializer deserializer.CTYDeserializer
|
|
|
|
repository repository.DynamoDBRepository
|
|
|
|
runner *terraform.ParallelResourceReader
|
|
|
|
}
|
|
|
|
|
2021-02-09 13:56:11 +00:00
|
|
|
func NewDynamoDBTableSupplier(provider *AWSTerraformProvider) *DynamoDBTableSupplier {
|
2021-02-11 11:21:49 +00:00
|
|
|
return &DynamoDBTableSupplier{
|
|
|
|
provider,
|
|
|
|
awsdeserializer.NewDynamoDBTableDeserializer(),
|
|
|
|
repository.NewDynamoDBRepository(provider.session),
|
|
|
|
terraform.NewParallelResourceReader(provider.Runner().SubRunner()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-17 15:54:53 +00:00
|
|
|
func (s *DynamoDBTableSupplier) Resources() ([]resource.Resource, error) {
|
2021-02-11 11:21:49 +00:00
|
|
|
tables, err := s.repository.ListAllTables()
|
|
|
|
if err != nil {
|
|
|
|
return nil, remoteerror.NewResourceEnumerationError(err, aws.AwsDynamodbTableResourceType)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, table := range tables {
|
|
|
|
table := table
|
|
|
|
s.runner.Run(func() (cty.Value, error) {
|
|
|
|
return s.readTable(table)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
retrieve, err := s.runner.Wait()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.deserializer.Deserialize(retrieve)
|
|
|
|
}
|
|
|
|
|
2021-03-17 15:54:53 +00:00
|
|
|
func (s *DynamoDBTableSupplier) readTable(tableName *string) (cty.Value, error) {
|
2021-02-11 11:21:49 +00:00
|
|
|
val, err := s.reader.ReadResource(terraform.ReadResourceArgs{
|
|
|
|
ID: *tableName,
|
|
|
|
Ty: aws.AwsDynamodbTableResourceType,
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"table_name": *tableName,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
logrus.Error(err)
|
|
|
|
return cty.NilVal, err
|
|
|
|
}
|
|
|
|
return *val, nil
|
|
|
|
}
|