driftctl/pkg/remote/aws/sqs_queue_policy_supplier.go

65 lines
1.8 KiB
Go
Raw Normal View History

2021-01-29 11:35:11 +00:00
package aws
import (
2021-02-03 20:08:57 +00:00
"github.com/cloudskiff/driftctl/pkg/remote/aws/repository"
2021-01-29 11:35:11 +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-29 11:35:11 +00:00
"github.com/cloudskiff/driftctl/pkg/terraform"
"github.com/sirupsen/logrus"
"github.com/zclconf/go-cty/cty"
)
type SqsQueuePolicySupplier 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-29 11:35:11 +00:00
runner *terraform.ParallelResourceReader
}
2021-05-31 15:39:16 +00:00
func NewSqsQueuePolicySupplier(provider *AWSTerraformProvider, deserializer *resource.Deserializer, client repository.SQSRepository) *SqsQueuePolicySupplier {
2021-01-29 11:35:11 +00:00
return &SqsQueuePolicySupplier{
provider,
2021-05-21 14:09:45 +00:00
deserializer,
2021-05-31 15:39:16 +00:00
client,
2021-01-29 11:35:11 +00:00
terraform.NewParallelResourceReader(provider.Runner().SubRunner()),
}
}
func (s *SqsQueuePolicySupplier) Resources() ([]resource.Resource, error) {
2021-02-03 20:08:57 +00:00
queues, err := s.client.ListAllQueues()
2021-01-29 11:35:11 +00:00
if err != nil {
return nil, remoteerror.NewResourceEnumerationErrorWithType(err, aws.AwsSqsQueuePolicyResourceType, aws.AwsSqsQueueResourceType)
}
for _, queue := range queues {
q := *queue
s.runner.Run(func() (cty.Value, error) {
return s.readSqsQueuePolicy(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.AwsSqsQueuePolicyResourceType, resources)
2021-01-29 11:35:11 +00:00
}
func (s *SqsQueuePolicySupplier) readSqsQueuePolicy(queueURL string) (cty.Value, error) {
2021-01-29 11:35:11 +00:00
var Ty resource.ResourceType = aws.AwsSqsQueuePolicyResourceType
val, err := s.reader.ReadResource(terraform.ReadResourceArgs{
Ty: Ty,
2021-02-03 20:08:57 +00:00
ID: queueURL,
2021-01-29 11:35:11 +00:00
})
if err != nil {
logrus.WithFields(logrus.Fields{
"type": Ty,
}).Error(err)
return cty.NilVal, err
}
return *val, nil
}