diff --git a/pkg/cloudprovider/providers/aws/aws.go b/pkg/cloudprovider/providers/aws/aws.go index e98e68aceb9..d96692adeb9 100644 --- a/pkg/cloudprovider/providers/aws/aws.go +++ b/pkg/cloudprovider/providers/aws/aws.go @@ -2046,17 +2046,22 @@ func ipPermissionExists(newPermission, existing *ec2.IpPermission, compareGroupU break } } - if found == false { + if !found { return false } } + for _, leftPair := range newPermission.UserIdGroupPairs { + found := false for _, rightPair := range existing.UserIdGroupPairs { if isEqualUserGroupPair(leftPair, rightPair, compareGroupUserIDs) { - return true + found = true + break } } - return false + if !found { + return false + } } return true diff --git a/pkg/cloudprovider/providers/aws/aws_test.go b/pkg/cloudprovider/providers/aws/aws_test.go index 440e03408a9..b1302510e63 100644 --- a/pkg/cloudprovider/providers/aws/aws_test.go +++ b/pkg/cloudprovider/providers/aws/aws_test.go @@ -879,6 +879,18 @@ func TestIpPermissionExistsHandlesMultipleGroupIds(t *testing.T) { if equals { t.Errorf("Should have not been considered equal since first is not in the second array of groups") } + + // The first pair matches, but the second does not + newIpPermission2 := ec2.IpPermission{ + UserIdGroupPairs: []*ec2.UserIdGroupPair{ + {GroupId: aws.String("firstGroupId")}, + {GroupId: aws.String("fourthGroupId")}, + }, + } + equals = ipPermissionExists(&newIpPermission2, &oldIpPermission, false) + if equals { + t.Errorf("Should have not been considered equal since first is not in the second array of groups") + } } func TestIpPermissionExistsHandlesRangeSubsets(t *testing.T) {