Skip to content

Commit 9b8b258

Browse files
authored
test: Adds removal of encryption at rest private endpoints in project cleanup (#3510)
* test: Adds removal of encryption at rest private endpoints in project cleanup * fix: Use constants for cloud provider names in encryption endpoint removal and add sleep after delete
1 parent 3a91a5c commit 9b8b258

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

internal/testutil/clean/org_clean_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ func removeProjectResources(ctx context.Context, t *testing.T, dryRun bool, clie
210210
if privateEndpointServicesRemoved > 0 {
211211
changes = append(changes, fmt.Sprintf("removed %d private endpoint services", privateEndpointServicesRemoved))
212212
}
213+
encryptionAtRestPrivateEndpointsRemoved := removeEncryptionAtRestPrivateEndpoints(ctx, t, dryRun, client, projectID)
214+
if encryptionAtRestPrivateEndpointsRemoved > 0 {
215+
changes = append(changes, fmt.Sprintf("removed %d encryption at rest private endpoints", encryptionAtRestPrivateEndpointsRemoved))
216+
}
213217
return strings.Join(changes, ", ")
214218
}
215219

@@ -397,3 +401,24 @@ func removeFederatedDatabases(ctx context.Context, t *testing.T, dryRun bool, cl
397401
}
398402
return len(federatedResults)
399403
}
404+
405+
func removeEncryptionAtRestPrivateEndpoints(ctx context.Context, t *testing.T, dryRun bool, client *admin.APIClient, projectID string) int {
406+
t.Helper()
407+
endpointsCount := 0
408+
for _, cloudProvider := range []string{constant.AWS, constant.AZURE} {
409+
privateEndpoints, _, err := client.EncryptionAtRestUsingCustomerKeyManagementApi.GetEncryptionAtRestPrivateEndpointsForCloudProvider(ctx, projectID, cloudProvider).Execute()
410+
require.NoError(t, err)
411+
endpoints := privateEndpoints.GetResults()
412+
endpointsCount += len(endpoints)
413+
for _, endpoint := range endpoints {
414+
endpointID := endpoint.GetId()
415+
t.Logf("delete encryption at rest private endpoint %s", endpointID)
416+
if !dryRun {
417+
_, err = client.EncryptionAtRestUsingCustomerKeyManagementApi.RequestEncryptionAtRestPrivateEndpointDeletion(ctx, projectID, cloudProvider, endpointID).Execute()
418+
require.NoError(t, err)
419+
time.Sleep(30 * time.Second)
420+
}
421+
}
422+
}
423+
return endpointsCount
424+
}

0 commit comments

Comments
 (0)