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

chore: cleanup google oidc providers after tests #13997

Merged
merged 2 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions packages/amplify-e2e-tests/src/cleanup-codebuild-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,23 @@ const getOrphanAppSyncApis = async (account: AWSAccountInfo, region: string): Pr
return staleApis?.map((it) => ({ apiId: it.apiId, name: it.name, region })) ?? [];
};

/**
* Get all OIDC providers in the account that match
*/
const deleteOrphanedOidcProviders = async (account: AWSAccountInfo): Promise<void> => {
const iamClient = new IAM(getAWSConfig(account));
const response = await iamClient.listOpenIDConnectProviders().promise();
if (response.OpenIDConnectProviderList) {
for (const provider of response.OpenIDConnectProviderList) {
// these seem to be the only offending resources at this time, but we can add more later
if (provider.Arn.endsWith('oidc-provider/accounts.google.com')) {
console.log('OIDC PROVIDER:', provider.Arn);
await iamClient.deleteOpenIDConnectProvider({ OpenIDConnectProviderArn: provider.Arn }).promise();
}
}
}
};

/**
* Get the relevant AWS config object for a given account and region.
*/
Expand Down Expand Up @@ -1041,6 +1058,7 @@ const cleanupAccount = async (account: AWSAccountInfo, accountIndex: number, fil

generateReport(staleResources);
await deleteResources(account, accountIndex, staleResources);
await deleteOrphanedOidcProviders(account);
console.log(`[ACCOUNT ${accountIndex}] Cleanup done!`);
};

Expand Down
18 changes: 18 additions & 0 deletions packages/amplify-e2e-tests/src/cleanup-e2e-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,23 @@ const getOrphanAppSyncApis = async (account: AWSAccountInfo, region: string): Pr
return staleApis.map((it) => ({ apiId: it.apiId, name: it.name, region }));
};

/**
* Get all OIDC providers in the account that match
*/
const deleteOrphanedOidcProviders = async (account: AWSAccountInfo): Promise<void> => {
const iamClient = new aws.IAM(getAWSConfig(account));
const response = await iamClient.listOpenIDConnectProviders().promise();
if (response.OpenIDConnectProviderList) {
for (const provider of response.OpenIDConnectProviderList) {
// these seem to be the only offending resources at this time, but we can add more later
if (provider.Arn.endsWith('oidc-provider/accounts.google.com')) {
console.log('OIDC PROVIDER:', provider.Arn);
await iamClient.deleteOpenIDConnectProvider({ OpenIDConnectProviderArn: provider.Arn }).promise();
}
}
}
};

/**
* Get the relevant AWS config object for a given account and region.
*/
Expand Down Expand Up @@ -934,6 +951,7 @@ const cleanupAccount = async (account: AWSAccountInfo, accountIndex: number, fil

generateReport(staleResources);
await deleteResources(account, accountIndex, staleResources);
await deleteOrphanedOidcProviders(account);
console.log(`[ACCOUNT ${accountIndex}] Cleanup done!`);
};

Expand Down
Loading