Merge pull request #1496 from snyk/fix_eip_weakness

fix: weakness in eip enumerator
main
Elie 2022-05-12 10:55:46 +02:00 committed by GitHub
commit 3817cf8c67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package aws package aws
import ( import (
"github.com/sirupsen/logrus"
"github.com/snyk/driftctl/pkg/remote/aws/repository" "github.com/snyk/driftctl/pkg/remote/aws/repository"
remoteerror "github.com/snyk/driftctl/pkg/remote/error" remoteerror "github.com/snyk/driftctl/pkg/remote/error"
"github.com/snyk/driftctl/pkg/resource" "github.com/snyk/driftctl/pkg/resource"
@ -32,6 +33,10 @@ func (e *EC2EipEnumerator) Enumerate() ([]*resource.Resource, error) {
results := make([]*resource.Resource, 0, len(addresses)) results := make([]*resource.Resource, 0, len(addresses))
for _, address := range addresses { for _, address := range addresses {
if address.AllocationId == nil {
logrus.Warn("Elastic IP does not have an allocation ID, ignoring")
continue
}
results = append( results = append(
results, results,
e.factory.CreateAbstractResource( e.factory.CreateAbstractResource(

View File

@ -232,7 +232,9 @@ func TestEC2Eip(t *testing.T) {
test: "no eips", test: "no eips",
dirName: "aws_ec2_eip_empty", dirName: "aws_ec2_eip_empty",
mocks: func(repository *repository.MockEC2Repository, alerter *mocks.AlerterInterface) { 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)
}, },
}, },
{ {