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

fix: cdk diff prints upgrade bootstrap warning even when current version exceeds the recommended version #29938

Merged
merged 12 commits into from
Apr 26, 2024
21 changes: 13 additions & 8 deletions packages/aws-cdk/lib/api/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,14 +533,16 @@ export class Deployments {
// try to assume the lookup role
const warningMessage = `Could not assume ${arns.lookupRoleArn}, proceeding anyway.`;
const upgradeMessage = `(To get rid of this warning, please upgrade to bootstrap version >= ${stack.lookupRole?.requiresBootstrapStackVersion})`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are unable to assume the lookup role and are not looking for the bootstrap version in SSM of the user's account, then there is no way we are sure about this recommendation. And, we should not just be recommending this without knowing it for a fact that they are on an older version of bootstrap.

We already error out if the user is using an older version of bootstrap than the recommended version.

try {
const stackSdk = await this.cachedSdkForEnvironment(resolvedEnvironment, Mode.ForReading, {
assumeRoleArn: arns.lookupRoleArn,
assumeRoleExternalId: stack.lookupRole?.assumeRoleExternalId,
});

const envResources = this.environmentResources.for(resolvedEnvironment, stackSdk.sdk);
const stackSdk = await this.cachedSdkForEnvironment(resolvedEnvironment, Mode.ForReading, {
assumeRoleArn: arns.lookupRoleArn,
assumeRoleExternalId: stack.lookupRole?.assumeRoleExternalId,
});

const envResources = this.environmentResources.for(resolvedEnvironment, stackSdk.sdk);
const stackBootstrapVersion = await envResources.getBootstrapVersion();

try {
// if we succeed in assuming the lookup role, make sure we have the correct bootstrap stack version
if (stackSdk.didAssumeRole && stack.lookupRole?.bootstrapStackVersionSsmParameter && stack.lookupRole.requiresBootstrapStackVersion) {
const version = await envResources.versionFromSsmParameter(stack.lookupRole.bootstrapStackVersionSsmParameter);
Expand All @@ -549,15 +551,18 @@ export class Deployments {
}
// we may not have assumed the lookup role because one was not provided
// if that is the case then don't print the upgrade warning
} else if (!stackSdk.didAssumeRole && stack.lookupRole?.requiresBootstrapStackVersion) {
} else if (!stackSdk.didAssumeRole && stack.lookupRole?.requiresBootstrapStackVersion &&
stack.lookupRole?.requiresBootstrapStackVersion > stackBootstrapVersion) {
warning(upgradeMessage);
}
return { ...stackSdk, resolvedEnvironment, envResources };
} catch (e: any) {
debug(e);
// only print out the warnings if the lookupRole exists AND there is a required
// bootstrap version, otherwise the warnings will print `undefined`
if (stack.lookupRole && stack.lookupRole.requiresBootstrapStackVersion) {
if (stack.lookupRole &&
stack.lookupRole.requiresBootstrapStackVersion &&
stack.lookupRole.requiresBootstrapStackVersion > stackBootstrapVersion) {
warning(warningMessage);
warning(upgradeMessage);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/aws-cdk/lib/api/environment-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ export class EnvironmentResources {

return { repositoryUri };
}

public async getBootstrapVersion() {
const bootstrapStack = await this.lookupToolkit();
return bootstrapStack.version;
}
}

export class NoBootstrapStackEnvironmentResources extends EnvironmentResources {
Expand Down
Loading