Skip to content

Commit 6bb4a46

Browse files
authoredDec 6, 2021
fix(aws-cdk): cdk diff always fails on diff (#17862)
In v1, the original behavior was that `cdk diff` exited 0 on a clean diff (no changes), and exited 1 on changes. #4721 introduced a new feature flag to always have `cdk diff` exit 0. As is standard, the "default" for the flag was `false`, but the future behavior was `true`, meaning any new CDK project created after that release (v1.19.0) defaulted to always exiting 0. In v2, the feature flag was expired, meaning users could no longer set it. Typically, the behavior (`FeatureFlags.isEnabled`) checks and errors if an expired flag is explicitly set, and always returns true for expired flags otherwise. However, the CDK CLI helper function did not contain this functionality. That means for current v2 projects, the v1-ported default value is used (false). This means `cdk diff` *always* exits 1 when there's a diff, and there's no way for a user to disable this behavior. This change updates the CLI behavior to default to true for expired flags, same as any other feature flag check; this means `cdk diff` will return to exiting 0, as v1 apps have been doing for years. The `FeatureFlags.isEnabled` method can't be used, as it requires a Construct node. I also took the liberty of explicitly setting the "default" to true for all expired flags, so any other direct access of the flag (not using the FeatureFlag library) will have the same consistent behavior.
1 parent 0cf7019 commit 6bb4a46

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed
 

‎packages/@aws-cdk/cx-api/lib/features.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,17 @@ export const FUTURE_FLAGS_EXPIRED: string[] = [
213213
*/
214214
const FUTURE_FLAGS_DEFAULTS: { [key: string]: boolean } = {
215215
[APIGATEWAY_USAGEPLANKEY_ORDERINSENSITIVE_ID]: true,
216-
[ENABLE_STACK_NAME_DUPLICATES_CONTEXT]: false,
217-
[ENABLE_DIFF_NO_FAIL_CONTEXT]: false,
216+
[ENABLE_STACK_NAME_DUPLICATES_CONTEXT]: true,
217+
[ENABLE_DIFF_NO_FAIL_CONTEXT]: true,
218218
[STACK_RELATIVE_EXPORTS_CONTEXT]: true,
219219
[NEW_STYLE_STACK_SYNTHESIS_CONTEXT]: true,
220-
[DOCKER_IGNORE_SUPPORT]: false,
221-
[SECRETS_MANAGER_PARSE_OWNED_SECRET_NAME]: false,
222-
[KMS_DEFAULT_KEY_POLICIES]: false,
223-
[S3_GRANT_WRITE_WITHOUT_ACL]: false,
224-
[ECS_REMOVE_DEFAULT_DESIRED_COUNT]: false,
220+
[DOCKER_IGNORE_SUPPORT]: true,
221+
[SECRETS_MANAGER_PARSE_OWNED_SECRET_NAME]: true,
222+
[KMS_DEFAULT_KEY_POLICIES]: true,
223+
[S3_GRANT_WRITE_WITHOUT_ACL]: true,
224+
[ECS_REMOVE_DEFAULT_DESIRED_COUNT]: true,
225225
[RDS_LOWERCASE_DB_IDENTIFIER]: true,
226-
[EFS_DEFAULT_ENCRYPTION_AT_REST]: false,
226+
[EFS_DEFAULT_ENCRYPTION_AT_REST]: true,
227227
[LAMBDA_RECOGNIZE_VERSION_PROPS]: false,
228228
[CLOUDFRONT_DEFAULT_SECURITY_POLICY_TLS_V1_2_2021]: true,
229229
};

‎packages/aws-cdk/bin/cdk.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,10 @@ function determineV2BootstrapSource(args: { template?: string }): BootstrapSourc
479479
}
480480

481481
function isFeatureEnabled(configuration: Configuration, featureFlag: string) {
482-
return configuration.context.get(featureFlag) ?? cxapi.futureFlagDefault(featureFlag);
482+
const context = configuration.context.get(featureFlag);
483+
return cxapi.FUTURE_FLAGS_EXPIRED.includes(featureFlag)
484+
? true
485+
: context ?? cxapi.futureFlagDefault(featureFlag);
483486
}
484487

485488
/**

0 commit comments

Comments
 (0)
Please sign in to comment.