Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NET-8391: fix cleanup script #3725

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion hack/aws-acceptance-test-cleanup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func realMain(ctx context.Context) error {
if err != nil {
return err
}
toDeleteVPCs = append(vpcsOutput.Vpcs)
toDeleteVPCs = append(toDeleteVPCs, vpcsOutput.Vpcs...)
nextToken = vpcsOutput.NextToken
if nextToken == nil {
break
Expand Down Expand Up @@ -366,6 +366,11 @@ func realMain(ctx context.Context) error {
},
},
})

if err != nil {
return err
}

vpcPeeringConnectionsToDelete := append(vpcPeeringConnectionsWithAcceptor.VpcPeeringConnections, vpcPeeringConnectionsWithRequester.VpcPeeringConnections...)

// Delete NAT gateways.
Expand All @@ -377,9 +382,11 @@ func realMain(ctx context.Context) error {
},
},
})

if err != nil {
return err
}

for _, gateway := range natGateways.NatGateways {
fmt.Printf("NAT gateway: Destroying... [id=%s]\n", *gateway.NatGatewayId)
_, err = ec2Client.DeleteNatGatewayWithContext(ctx, &ec2.DeleteNatGatewayInput{
Expand Down Expand Up @@ -484,6 +491,11 @@ func realMain(ctx context.Context) error {
},
},
})

if err != nil {
return err
}

for _, igw := range igws.InternetGateways {
fmt.Printf("Internet gateway: Detaching from VPC... [id=%s]\n", *igw.InternetGatewayId)
if err := destroyBackoff(ctx, "Internet Gateway", *igw.InternetGatewayId, func() error {
Expand Down Expand Up @@ -520,6 +532,11 @@ func realMain(ctx context.Context) error {
},
},
})

if err != nil {
return err
}

for _, subnet := range subnets.Subnets {
fmt.Printf("Subnet: Destroying... [id=%s]\n", *subnet.SubnetId)
if err := destroyBackoff(ctx, "Subnet", *subnet.SubnetId, func() error {
Expand Down Expand Up @@ -547,6 +564,11 @@ func realMain(ctx context.Context) error {
},
},
})

if err != nil {
return err
}

for _, routeTable := range routeTables.RouteTables {
// Find out if this is the main route table.
var mainRouteTable bool
Expand Down Expand Up @@ -580,6 +602,11 @@ func realMain(ctx context.Context) error {
},
},
})

if err != nil {
return err
}

for _, sg := range sgs.SecurityGroups {
if len(sg.IpPermissions) > 0 {
revokeSGInput := &ec2.RevokeSecurityGroupIngressInput{GroupId: sg.GroupId}
Expand Down
Loading