2021-07-22 09:35:20 +00:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2021-07-28 14:30:22 +00:00
|
|
|
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
|
2021-07-22 09:35:20 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/resource"
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/resource/aws"
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/terraform"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SQSQueueDetailsFetcher struct {
|
|
|
|
reader terraform.ResourceReader
|
|
|
|
deserializer *resource.Deserializer
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSQSQueueDetailsFetcher(provider terraform.ResourceReader, deserializer *resource.Deserializer) *SQSQueueDetailsFetcher {
|
|
|
|
return &SQSQueueDetailsFetcher{
|
|
|
|
reader: provider,
|
|
|
|
deserializer: deserializer,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-09 14:03:04 +00:00
|
|
|
func (r *SQSQueueDetailsFetcher) ReadDetails(res *resource.Resource) (*resource.Resource, error) {
|
2021-07-22 09:35:20 +00:00
|
|
|
ctyVal, err := r.reader.ReadResource(terraform.ReadResourceArgs{
|
2021-08-18 13:58:28 +00:00
|
|
|
ID: res.ResourceId(),
|
2021-07-22 09:35:20 +00:00
|
|
|
Ty: aws.AwsSqsQueueResourceType,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
if strings.Contains(err.Error(), "NonExistentQueue") {
|
|
|
|
logrus.WithFields(logrus.Fields{
|
2021-08-18 13:58:28 +00:00
|
|
|
"id": res.ResourceId(),
|
2021-07-22 09:35:20 +00:00
|
|
|
"type": aws.AwsSqsQueueResourceType,
|
|
|
|
}).Debugf("Ignoring queue that seems to be already deleted: %+v", err)
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
logrus.Error(err)
|
2021-08-18 13:58:28 +00:00
|
|
|
return nil, remoteerror.NewResourceScanningError(err, res.ResourceType(), res.ResourceId())
|
2021-07-22 09:35:20 +00:00
|
|
|
}
|
|
|
|
deserializedRes, err := r.deserializer.DeserializeOne(aws.AwsSqsQueueResourceType, *ctyVal)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return deserializedRes, nil
|
|
|
|
}
|