Skip to content

Commit 45bc57a

Browse files
authored
fix(cli): pathMetadata and assetMetadata defaults cannot be configured in cdk.json (#24533)
Previously, pathMetadata, assetMetadata, debug and staging could not be set in `cdk.json` as command-line parameters defaults would always overwrite this. In particular, this `cdk.json` would be ignored: ``` { "app": "npx ts-node --prefer-ts-exts bin/example", ... "pathMetadata": false, "assetMetadata": false } ``` The issue is this piece of code: ``` this.settings = this.defaultConfig .merge(userConfig) .merge(this.projectConfig) .merge(this.commandLineArguments) .makeReadOnly(); ``` `commandLineArguments` returns true for the above mentioned options. This commit is a copy of #21891 which fell through the cracks, so I'm picking up as this can potentially cause outages to resources that have drift under the hood, and adding metadata looks like an `Update` operation to CloudFormation. There are already unit tests around the cli which show that the same behavior works, located here: https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli.integtest.ts shoutout to @berenddeboer who did the work, I'm just reviving it. Closes #3573 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b7044fb commit 45bc57a

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

packages/aws-cdk/lib/cli.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ async function parseCommandLineArguments(args: string[]) {
7777
.option('ca-bundle-path', { type: 'string', desc: 'Path to CA certificate to use when validating HTTPS requests. Will read from AWS_CA_BUNDLE environment variable if not specified', requiresArg: true })
7878
.option('ec2creds', { type: 'boolean', alias: 'i', default: undefined, desc: 'Force trying to fetch EC2 instance credentials. Default: guess EC2 instance status' })
7979
.option('version-reporting', { type: 'boolean', desc: 'Include the "AWS::CDK::Metadata" resource in synthesized templates (enabled by default)', default: undefined })
80-
.option('path-metadata', { type: 'boolean', desc: 'Include "aws:cdk:path" CloudFormation metadata for each resource (enabled by default)', default: true })
81-
.option('asset-metadata', { type: 'boolean', desc: 'Include "aws:asset:*" CloudFormation metadata for resources that uses assets (enabled by default)', default: true })
80+
.option('path-metadata', { type: 'boolean', desc: 'Include "aws:cdk:path" CloudFormation metadata for each resource (enabled by default)', default: undefined })
81+
.option('asset-metadata', { type: 'boolean', desc: 'Include "aws:asset:*" CloudFormation metadata for resources that uses assets (enabled by default)', default: undefined })
8282
.option('role-arn', { type: 'string', alias: 'r', desc: 'ARN of Role to use when invoking CloudFormation', default: undefined, requiresArg: true })
8383
.option('staging', { type: 'boolean', desc: 'Copy assets to the output directory (use --no-staging to disable the copy of assets which allows local debugging via the SAM CLI to reference the original source files)', default: true })
8484
.option('output', { type: 'string', alias: 'o', desc: 'Emits the synthesized cloud assembly into a directory (default: cdk.out)', requiresArg: true })

packages/aws-cdk/lib/settings.ts

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export class Configuration {
7474

7575
public readonly defaultConfig = new Settings({
7676
versionReporting: true,
77+
assetMetadata: true,
7778
pathMetadata: true,
7879
output: 'cdk.out',
7980
});

0 commit comments

Comments
 (0)