Skip to content

(flags): cdk flags --set --unconfigured --recommended writes false when exactly one flag is unconfigured #2048

Open

Description

@jroru

Describe the bug

When exactly one boolean feature flag is unconfigured, cdk flags --set --unconfigured --recommended shows the recommended value in its preview, but writes false to cdk.json.

This is the bug that #1183 fixed for --all. The fix added !params.all to the single-flag check in modifyValues, so --unconfigured still takes the single-flag path.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

The flag is written with its recommended value, as the preview shows.

Current Behavior

Flag changes:
  @aws-cdk/aws-cloudfront:defaultViewerProtocolPolicyRedirectToHttps: <unset> → true
Setting flag '@aws-cdk/aws-cloudfront:defaultViewerProtocolPolicyRedirectToHttps' to: false
Flag value(s) updated successfully.

cdk.json then contains "@aws-cdk/aws-cloudfront:defaultViewerProtocolPolicyRedirectToHttps": false.

Reproduction Steps

  1. Create an app with aws-cdk-lib 2.273.0 whose cdk.json sets every boolean feature flag except @aws-cdk/aws-cloudfront:defaultViewerProtocolPolicyRedirectToHttps (recommended value true).
  2. Run cdk flags --unstable=flags --set --unconfigured --recommended --yes.
  3. The flag is written as false.

With two or more unconfigured flags, the recommended values are written correctly.

Possible Solution

In FlagOperations.modifyValues (packages/aws-cdk/lib/commands/flags/operations.ts), the single-flag branch is meant for cdk flags --set FLAGNAME --value X, but it does not check that --value was given:

if (flagNames.length === 1 && !params.safe && !params.all) {
  const boolValue = params.value === 'true';   // undefined → false

buildUpdateObject uses flagNames.length === 1 && params.value !== undefined. Using the same condition in modifyValues would cover --unconfigured and any other multi-flag mode, not only --all.

Additional Information/Context

Related: #1183 (same bug, fixed for --all only).

CDK CLI Version

2.1145.0 (build 13877dc)

Framework Version

aws-cdk-lib 2.273.0

Node.js Version

v24.20.0

OS

Linux (Amazon Linux 2023)

Language

TypeScript

Language Version

No response

Other information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions