2021-02-04 15:11:51 +00:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/aws/aws-sdk-go/service/sns"
|
|
|
|
"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/resource"
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/resource/aws"
|
2021-05-21 14:09:45 +00:00
|
|
|
|
2021-02-04 15:11:51 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SNSTopicPolicySupplier struct {
|
|
|
|
reader terraform.ResourceReader
|
2021-05-21 14:09:45 +00:00
|
|
|
deserializer *resource.Deserializer
|
2021-02-04 15:11:51 +00:00
|
|
|
client repository.SNSRepository
|
|
|
|
runner *terraform.ParallelResourceReader
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:09:45 +00:00
|
|
|
func NewSNSTopicPolicySupplier(provider *AWSTerraformProvider, deserializer *resource.Deserializer) *SNSTopicPolicySupplier {
|
2021-02-04 15:11:51 +00:00
|
|
|
return &SNSTopicPolicySupplier{
|
|
|
|
provider,
|
2021-05-21 14:09:45 +00:00
|
|
|
deserializer,
|
2021-02-04 15:11:51 +00:00
|
|
|
repository.NewSNSClient(provider.session),
|
|
|
|
terraform.NewParallelResourceReader(provider.Runner().SubRunner()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-17 15:54:53 +00:00
|
|
|
func (s *SNSTopicPolicySupplier) Resources() ([]resource.Resource, error) {
|
2021-02-04 15:11:51 +00:00
|
|
|
topics, err := s.client.ListAllTopics()
|
|
|
|
if err != nil {
|
|
|
|
return nil, remoteerror.NewResourceEnumerationErrorWithType(err, aws.AwsSnsTopicPolicyResourceType, aws.AwsSnsTopicResourceType)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, topic := range topics {
|
|
|
|
topic := *topic
|
|
|
|
s.runner.Run(func() (cty.Value, error) {
|
|
|
|
return s.readTopicPolicy(topic)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
retrieve, err := s.runner.Wait()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:09:45 +00:00
|
|
|
return s.deserializer.Deserialize(aws.AwsSnsTopicPolicyResourceType, retrieve)
|
2021-02-04 15:11:51 +00:00
|
|
|
}
|
|
|
|
|
2021-03-17 15:54:53 +00:00
|
|
|
func (s *SNSTopicPolicySupplier) readTopicPolicy(topic sns.Topic) (cty.Value, error) {
|
2021-02-04 15:11:51 +00:00
|
|
|
val, err := s.reader.ReadResource(terraform.ReadResourceArgs{
|
|
|
|
ID: *topic.TopicArn,
|
|
|
|
Ty: aws.AwsSnsTopicPolicyResourceType,
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"topic_arn": *topic.TopicArn,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
logrus.Error(err)
|
|
|
|
return cty.NilVal, err
|
|
|
|
}
|
|
|
|
return *val, nil
|
|
|
|
}
|