Merge pull request #868 from cloudskiff/fix/sqs_queue_race

fix crash when sqs queue is just deleted and still appears in listing
main
Martin 2021-07-22 15:50:53 +02:00 committed by GitHub
commit f7d79529b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 2 deletions

View File

@ -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))

View File

@ -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
}

View File

@ -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()