From a73d47c33dfa6003ff8e4fb6a25cf86255f2206b Mon Sep 17 00:00:00 2001 From: Elie Date: Thu, 12 May 2022 10:33:29 +0200 Subject: [PATCH] fix: weakness in eip enumerator --- pkg/remote/aws/ec2_eip_enumerator.go | 5 +++++ pkg/remote/aws_ec2_scanner_test.go | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/remote/aws/ec2_eip_enumerator.go b/pkg/remote/aws/ec2_eip_enumerator.go index 56bf945b..9513c62e 100644 --- a/pkg/remote/aws/ec2_eip_enumerator.go +++ b/pkg/remote/aws/ec2_eip_enumerator.go @@ -1,6 +1,7 @@ package aws import ( + "github.com/sirupsen/logrus" "github.com/snyk/driftctl/pkg/remote/aws/repository" remoteerror "github.com/snyk/driftctl/pkg/remote/error" "github.com/snyk/driftctl/pkg/resource" @@ -32,6 +33,10 @@ func (e *EC2EipEnumerator) Enumerate() ([]*resource.Resource, error) { results := make([]*resource.Resource, 0, len(addresses)) for _, address := range addresses { + if address.AllocationId == nil { + logrus.Warn("Elastic IP does not have an allocation ID, ignoring") + continue + } results = append( results, e.factory.CreateAbstractResource( diff --git a/pkg/remote/aws_ec2_scanner_test.go b/pkg/remote/aws_ec2_scanner_test.go index 2c615446..49ea7c51 100644 --- a/pkg/remote/aws_ec2_scanner_test.go +++ b/pkg/remote/aws_ec2_scanner_test.go @@ -232,7 +232,9 @@ func TestEC2Eip(t *testing.T) { test: "no eips", dirName: "aws_ec2_eip_empty", mocks: func(repository *repository.MockEC2Repository, alerter *mocks.AlerterInterface) { - repository.On("ListAllAddresses").Return([]*ec2.Address{}, nil) + repository.On("ListAllAddresses").Return([]*ec2.Address{ + {}, // Test Eip without AllocationId because it can happen (seen in sentry) + }, nil) }, }, {