Skip to content

Commit

Permalink
Merge pull request #604 from cloudskiff/fix/cp_fix_601
Browse files Browse the repository at this point in the history
- backport fix to #601 in 0.9
  • Loading branch information
eliecharra authored and Martin Guibert committed Jun 8, 2021
2 parents b933a9b + 58d3956 commit 99f67fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
15 changes: 9 additions & 6 deletions pkg/remote/aws/sns_topic_subscription_supplier.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

awssdk "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/sns"
"github.com/sirupsen/logrus"
"github.com/zclconf/go-cty/cty"
Expand All @@ -19,17 +20,19 @@ import (
"github.com/cloudskiff/driftctl/pkg/terraform"
)

type pendingTopicAlert struct {
type wrongArnTopicAlert struct {
arn string
endpoint *string
}

func (p *pendingTopicAlert) Message() string {
return fmt.Sprintf("%s with pending confirmation status for endpoint \"%s\" will be ignored",
func (p *wrongArnTopicAlert) Message() string {
return fmt.Sprintf("%s with incorrect subscription arn (%s) for endpoint \"%s\" will be ignored",
aws.AwsSnsTopicSubscriptionResourceType,
p.arn,
awssdk.StringValue(p.endpoint))
}

func (p *pendingTopicAlert) ShouldIgnoreResource() bool {
func (p *wrongArnTopicAlert) ShouldIgnoreResource() bool {
return false
}

Expand Down Expand Up @@ -72,10 +75,10 @@ func (s *SNSTopicSubscriptionSupplier) Resources() ([]resource.Resource, error)
}

func (s *SNSTopicSubscriptionSupplier) readTopicSubscription(subscription *sns.Subscription, alertr alerter.AlerterInterface) (cty.Value, error) {
if subscription.SubscriptionArn != nil && *subscription.SubscriptionArn == "PendingConfirmation" {
if subscription.SubscriptionArn != nil && !arn.IsARN(*subscription.SubscriptionArn) {
alertr.SendAlert(
fmt.Sprintf("%s.%s", aws.AwsSnsTopicSubscriptionResourceType, *subscription.SubscriptionArn),
&pendingTopicAlert{subscription.Endpoint},
&wrongArnTopicAlert{*subscription.SubscriptionArn, subscription.Endpoint},
)
return cty.NilVal, nil
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/remote/aws/sns_topic_subscription_supplier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,22 @@ func TestSNSTopicSubscriptionSupplier_Resources(t *testing.T) {
err: nil,
},
{
test: "Multiple SNSTopic Subscription with one pending",
test: "Multiple SNSTopic Subscription with one pending and one incorrect",
dirName: "sns_topic_subscription_multiple",
mocks: func(client *mocks.SNSRepository) {
client.On("ListAllSubscriptions").Return([]*sns.Subscription{
{SubscriptionArn: aws.String("PendingConfirmation"), Endpoint: aws.String("TEST")},
{SubscriptionArn: aws.String("Incorrect"), Endpoint: aws.String("INCORRECT")},
{SubscriptionArn: aws.String("arn:aws:sns:us-east-1:526954929923:user-updates-topic2:c0f794c5-a009-4db4-9147-4c55959787fa")},
{SubscriptionArn: aws.String("arn:aws:sns:us-east-1:526954929923:user-updates-topic:b6e66147-2b31-4486-8d4b-2a2272264c8e")},
}, nil)
},
alerts: map[string][]alerter.Alert{
"aws_sns_topic_subscription.PendingConfirmation": []alerter.Alert{
&pendingTopicAlert{aws.String("TEST")},
&wrongArnTopicAlert{"PendingConfirmation", aws.String("TEST")},
},
"aws_sns_topic_subscription.Incorrect": []alerter.Alert{
&wrongArnTopicAlert{"Incorrect", aws.String("INCORRECT")},
},
},
err: nil,
Expand Down

0 comments on commit 99f67fb

Please sign in to comment.