diff --git a/test/e2e/datafederation_pe_test.go b/test/e2e/datafederation_pe_test.go index e4ab27c28f..4b1023276c 100644 --- a/test/e2e/datafederation_pe_test.go +++ b/test/e2e/datafederation_pe_test.go @@ -15,6 +15,7 @@ import ( "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/config" "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/data" "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/model" + "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/utils" "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/resources" ) @@ -75,7 +76,11 @@ var _ = Describe("UserLogin", Label("datafederation"), func() { vpcId := providerAction.SetupNetwork( "AWS", - cloud.WithAWSConfig(&cloud.AWSConfig{Region: config.AWSRegionEU}), + cloud.WithAWSConfig(&cloud.AWSConfig{ + VPC: utils.RandomName("datafederation-private-endpoint"), + Region: config.AWSRegionEU, + EnableCleanup: true, + }), ) pe = providerAction.SetupPrivateEndpoint( &cloud.AWSPrivateEndpointRequest{ diff --git a/test/helper/e2e/actions/cloud/aws.go b/test/helper/e2e/actions/cloud/aws.go index 4cc1b0d184..2a771fac0c 100644 --- a/test/helper/e2e/actions/cloud/aws.go +++ b/test/helper/e2e/actions/cloud/aws.go @@ -6,8 +6,10 @@ import ( "fmt" "os" "strings" + "time" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/kms" @@ -280,6 +282,34 @@ func (a *AwsAction) CreatePrivateEndpoint(serviceName, privateEndpointName, regi if err != nil { a.t.Error(err) } + + timeout := 10 * time.Minute + start := time.Now() + for { + a.t.Log(fmt.Sprintf("deleting VPC ID %q since %v", aws.StringValue(result.VpcEndpoint.VpcEndpointId), time.Since(start))) + + output, err := ec2Client.DescribeVpcEndpoints(&ec2.DescribeVpcEndpointsInput{ + VpcEndpointIds: []*string{result.VpcEndpoint.VpcEndpointId}, + }) + + var e awserr.Error + if (errors.As(err, &e) && e.Code() == "InvalidVpcEndpointId.NotFound") || len(output.VpcEndpoints) == 0 { + return + } + + if err != nil { + a.t.Error(err) + return + } + + if time.Since(start) > timeout { + a.t.Error(errors.New("timeout waiting for deletion of vpc endpoints")) + return + } + + // we do know that deletion of VPC endpoints takes time + time.Sleep(3 * time.Second) + } }) return *result.VpcEndpoint.VpcEndpointId, nil