diff --git a/tests/e2e/hcp_machine_pool_test.go b/tests/e2e/hcp_machine_pool_test.go index 4e919ed2..f37d56ae 100644 --- a/tests/e2e/hcp_machine_pool_test.go +++ b/tests/e2e/hcp_machine_pool_test.go @@ -263,7 +263,7 @@ var _ = Describe("HCP MachinePool", ci.Day2, ci.FeatureMachinepool, func() { Replicas: helper.IntPointer(replicas), MachineType: helper.StringPointer(machineType), Name: helper.StringPointer(name), - AdditionalSecurityGroups: helper.StringSlicePointer(output.SGIDs), + AdditionalSecurityGroups: helper.StringSlicePointer(sgIDs), AutoscalingEnabled: helper.BoolPointer(false), AutoRepair: helper.BoolPointer(false), SubnetID: helper.StringPointer(vpcOutput.PrivateSubnets[0]), diff --git a/tests/utils/helper/vpc_dependency_fetcher.go b/tests/utils/helper/vpc_dependency_fetcher.go new file mode 100644 index 00000000..29df97e7 --- /dev/null +++ b/tests/utils/helper/vpc_dependency_fetcher.go @@ -0,0 +1,91 @@ +package helper + +import ( + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/ec2" + . "github.com/terraform-redhat/terraform-provider-rhcs/tests/utils/log" +) + +func DescribeInstances(vpcID string, region string) ([]string, error) { + sess := session.Must(session.NewSession(&aws.Config{ + Region: aws.String(region), + })) + ec := ec2.New(sess) + var instanceIDs []string + instances, err := ec.DescribeInstances(&ec2.DescribeInstancesInput{ + Filters: []*ec2.Filter{ + { + Name: aws.String("vpc-id"), + Values: []*string{aws.String(vpcID)}, + }, + { + Name: aws.String("instance-state-name"), + Values: []*string{aws.String("pending"), aws.String("running"), aws.String("shutting-down"), aws.String("stopped"), aws.String("stopping")}, + }, + }, + }) + if err != nil { + return instanceIDs, err + } + + for _, reservation := range instances.Reservations { + for _, instance := range reservation.Instances { + instanceIDs = append(instanceIDs, *instance.InstanceId) + Logger.Warnf("Instance ID(Reservation Id %s) %s may leak!", *reservation.ReservationId, *instance.InstanceId) + } + } + return instanceIDs, nil +} + +func DescribeNatGateways(vpcID string, region string) ([]string, error) { + sess := session.Must(session.NewSession(&aws.Config{ + Region: aws.String(region), + })) + ec := ec2.New(sess) + var natGatewayIDs []string + natGateways, err := ec.DescribeNatGateways(&ec2.DescribeNatGatewaysInput{ + Filter: []*ec2.Filter{ + { + Name: aws.String("vpc-id"), + Values: []*string{aws.String(vpcID)}, + }, + { + Name: aws.String("state"), + Values: []*string{aws.String("available"), aws.String("deleting"), aws.String("pending")}, + }, + }, + }) + if err != nil { + return natGatewayIDs, err + } + for _, ngw := range natGateways.NatGateways { + natGatewayIDs = append(natGatewayIDs, *ngw.NatGatewayId) + Logger.Warnf("NatGateway Id %s may leak!", *ngw.NatGatewayId) + } + return natGatewayIDs, nil +} + +func DescribeNetworkInterfaces(vpcID string, region string) ([]string, error) { + sess := session.Must(session.NewSession(&aws.Config{ + Region: aws.String(region), + })) + ec := ec2.New(sess) + var networkInterfaceIDs []string + networkInterfaces, err := ec.DescribeNetworkInterfaces(&ec2.DescribeNetworkInterfacesInput{ + Filters: []*ec2.Filter{ + { + Name: aws.String("vpc-id"), + Values: []*string{aws.String(vpcID)}, + }, + }, + }) + if err != nil { + return networkInterfaceIDs, err + } + for _, ni := range networkInterfaces.NetworkInterfaces { + networkInterfaceIDs = append(networkInterfaceIDs, *ni.NetworkInterfaceId) + Logger.Warnf("NetworkInterface Id %s may leak!", *ni.NetworkInterfaceId) + } + return networkInterfaceIDs, nil +} diff --git a/tests/utils/profilehandler/handler.go b/tests/utils/profilehandler/handler.go index b119802a..e082e4be 100644 --- a/tests/utils/profilehandler/handler.go +++ b/tests/utils/profilehandler/handler.go @@ -1056,8 +1056,41 @@ func (ctx *profileContext) DestroyRHCSClusterResources(token string) error { } else { _, err = vpcService.Destroy() if err != nil { - errs = append(errs, err) + if ctx.profile.PrivateLink { + if strings.Contains(err.Error(), "DependencyViolation") { + Logger.Warn("DependencyViolation, waiting for 5 minutes before retrying...") + time.Sleep(5 * time.Minute) + _, err = vpcService.Destroy() + if err != nil { + errs = append(errs, err) + if strings.Contains(err.Error(), "DependencyViolation") { + vpcOutPut, err := vpcService.Output() + if err != nil { + Logger.Errorf("It met error when try to get the vpc output: %s", err.Error()) + } else { + instances, err := helper.DescribeInstances(vpcOutPut.VPCID, ctx.profile.Region) + if err != nil { + Logger.Errorf("It met error when try to get the instances: %s", err.Error()) + } + natGateways, err := helper.DescribeNatGateways(vpcOutPut.VPCID, ctx.profile.Region) + if err != nil { + Logger.Errorf("It met error when try to get natGateways: %s", err.Error()) + } + networkInterfaces, err := helper.DescribeNetworkInterfaces(vpcOutPut.VPCID, ctx.profile.Region) + if err != nil { + Logger.Errorf("It met error when try to get networkInterfaces: %s", err.Error()) + } + Logger.Warnf("Instance %v and natGateways %v and networkInterfaces %v may leak!", instances, natGateways, networkInterfaces) + } + } + + } + } + } else { + errs = append(errs, err) + } } + } } if ctx.profile.STS {