driftctl/pkg/remote/aws/sqs_queue_supplier.go

65 lines
1.7 KiB
Go
Raw Normal View History

2021-01-27 10:49:25 +00:00
package aws
import (
2021-02-03 20:08:57 +00:00
"github.com/cloudskiff/driftctl/pkg/remote/aws/repository"
2021-01-27 10:49:25 +00:00
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
"github.com/cloudskiff/driftctl/pkg/resource"
"github.com/cloudskiff/driftctl/pkg/resource/aws"
2021-05-21 14:09:45 +00:00
2021-01-27 10:49:25 +00:00
"github.com/cloudskiff/driftctl/pkg/terraform"
"github.com/sirupsen/logrus"
"github.com/zclconf/go-cty/cty"
)
type SqsQueueSupplier struct {
reader terraform.ResourceReader
2021-05-21 14:09:45 +00:00
deserializer *resource.Deserializer
2021-02-03 20:08:57 +00:00
client repository.SQSRepository
2021-01-27 10:49:25 +00:00
runner *terraform.ParallelResourceReader
}
2021-05-31 15:39:16 +00:00
func NewSqsQueueSupplier(provider *AWSTerraformProvider, deserializer *resource.Deserializer, client repository.SQSRepository) *SqsQueueSupplier {
2021-01-27 10:49:25 +00:00
return &SqsQueueSupplier{
provider,
2021-05-21 14:09:45 +00:00
deserializer,
2021-05-31 15:39:16 +00:00
client,
2021-01-27 10:49:25 +00:00
terraform.NewParallelResourceReader(provider.Runner().SubRunner()),
}
}
func (s *SqsQueueSupplier) Resources() ([]resource.Resource, error) {
2021-02-03 20:08:57 +00:00
queues, err := s.client.ListAllQueues()
2021-01-27 10:49:25 +00:00
if err != nil {
return nil, remoteerror.NewResourceEnumerationError(err, aws.AwsSqsQueueResourceType)
}
for _, queue := range queues {
q := *queue
s.runner.Run(func() (cty.Value, error) {
return s.readSqsQueue(q)
})
}
resources, err := s.runner.Wait()
if err != nil {
return nil, err
}
2021-05-21 14:09:45 +00:00
return s.deserializer.Deserialize(aws.AwsSqsQueueResourceType, resources)
2021-01-27 10:49:25 +00:00
}
func (s *SqsQueueSupplier) readSqsQueue(queueURL string) (cty.Value, error) {
2021-01-27 10:49:25 +00:00
var Ty resource.ResourceType = aws.AwsSqsQueueResourceType
val, err := s.reader.ReadResource(terraform.ReadResourceArgs{
Ty: Ty,
2021-02-03 20:08:57 +00:00
ID: queueURL,
2021-01-27 10:49:25 +00:00
})
if err != nil {
logrus.WithFields(logrus.Fields{
"type": Ty,
}).Error(err)
return cty.NilVal, err
}
return *val, nil
}