Merge pull request #868 from cloudskiff/fix/sqs_queue_race
fix crash when sqs queue is just deleted and still appears in listingmain
commit
f7d79529b1
|
@ -133,7 +133,7 @@ func Init(version string, alerter *alerter.Alerter,
|
|||
remoteLibrary.AddDetailsFetcher(aws.AwsDbSubnetGroupResourceType, common.NewGenericDetailsFetcher(aws.AwsDbSubnetGroupResourceType, provider, deserializer))
|
||||
|
||||
remoteLibrary.AddEnumerator(NewSQSQueueEnumerator(sqsRepository, factory))
|
||||
remoteLibrary.AddDetailsFetcher(aws.AwsSqsQueueResourceType, common.NewGenericDetailsFetcher(aws.AwsSqsQueueResourceType, provider, deserializer))
|
||||
remoteLibrary.AddDetailsFetcher(aws.AwsSqsQueueResourceType, NewSQSQueueDetailsFetcher(provider, deserializer))
|
||||
remoteLibrary.AddEnumerator(NewSQSQueuePolicyEnumerator(sqsRepository, factory))
|
||||
remoteLibrary.AddDetailsFetcher(aws.AwsSqsQueuePolicyResourceType, common.NewGenericDetailsFetcher(aws.AwsSqsQueuePolicyResourceType, provider, deserializer))
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"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,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *SQSQueueDetailsFetcher) ReadDetails(res resource.Resource) (resource.Resource, error) {
|
||||
ctyVal, err := r.reader.ReadResource(terraform.ReadResourceArgs{
|
||||
ID: res.TerraformId(),
|
||||
Ty: aws.AwsSqsQueueResourceType,
|
||||
})
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "NonExistentQueue") {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"id": res.TerraformId(),
|
||||
"type": aws.AwsSqsQueueResourceType,
|
||||
}).Debugf("Ignoring queue that seems to be already deleted: %+v", err)
|
||||
return nil, nil
|
||||
}
|
||||
logrus.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
deserializedRes, err := r.deserializer.DeserializeOne(aws.AwsSqsQueueResourceType, *ctyVal)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return deserializedRes, nil
|
||||
}
|
|
@ -101,7 +101,7 @@ func TestSQSQueue(t *testing.T) {
|
|||
}
|
||||
|
||||
remoteLibrary.AddEnumerator(aws.NewSQSQueueEnumerator(repo, factory))
|
||||
remoteLibrary.AddDetailsFetcher(resourceaws.AwsSqsQueueResourceType, common.NewGenericDetailsFetcher(resourceaws.AwsSqsQueueResourceType, provider, deserializer))
|
||||
remoteLibrary.AddDetailsFetcher(resourceaws.AwsSqsQueueResourceType, aws.NewSQSQueueDetailsFetcher(provider, deserializer))
|
||||
|
||||
s := NewScanner(nil, remoteLibrary, alerter, scanOptions)
|
||||
got, err := s.Resources()
|
||||
|
|
Loading…
Reference in New Issue