diff --git a/packages/aws-cdk/lib/cli/cdk-toolkit.ts b/packages/aws-cdk/lib/cli/cdk-toolkit.ts index 6a35c83b3..9f1e88eef 100644 --- a/packages/aws-cdk/lib/cli/cdk-toolkit.ts +++ b/packages/aws-cdk/lib/cli/cdk-toolkit.ts @@ -2113,11 +2113,29 @@ async function askUserConfirmation( }); } +/** + * Display a warning if there are flags that are different from the recommended value + * + * This happens if both of the following are true: + * + * - The user didn't configure the value + * - The default value for the flag (unconfiguredBehavesLike) is different from the recommended value + */ export async function displayFlagsMessage(ioHost: IoHelper, toolkit: InternalToolkit, cloudExecutable: CloudExecutable): Promise { - let numUnconfigured = (await toolkit.flags(cloudExecutable)) + const flags = await toolkit.flags(cloudExecutable); + + // The "unconfiguredBehavesLike" information got added later. If none of the flags have this information, + // we don't have enough information to reliably display this information without scaring users, so don't do anything. + if (flags.every(flag => flag.unconfiguredBehavesLike === undefined)) { + return; + } + + const unconfiguredFlags = flags .filter(flag => !OBSOLETE_FLAGS.includes(flag.name)) - .filter(flag => flag.userValue === undefined).length; + .filter(flag => (flag.unconfiguredBehavesLike?.v2 ?? false) !== flag.recommendedValue) + .filter(flag => flag.userValue === undefined); + const numUnconfigured = unconfiguredFlags.length; if (numUnconfigured > 0) { await ioHost.defaults.warn(`${numUnconfigured} feature flags are not configured. Run 'cdk --unstable=flags flags' to learn more.`); }