Skip to content

Commit

Permalink
fix(cloudformation-include): string arrays inside unknown properties …
Browse files Browse the repository at this point in the history
…cannot be parsed (#32461)

We are using `this` to refer to static methods, which fails at runtime. Use the class name instead.

Fixes #32454.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
otaviomacedo authored Dec 11, 2024
1 parent 0f5fe9a commit 0c2f98b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"AutoScalingGroup": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"DesiredCapacity": "1",
"MinSize": "1",
"MaxSize": "5"
},
"CreationPolicy": {
"ResourceSignal": {
"Count": 1,
"Timeout": "PT10M"
}
},
"UpdatePolicy": {
"AutoScalingRollingUpdate": {
"PauseTime": "PT10M",
"SuspendProcesses": [
"HealthCheck",
"ReplaceUnhealthy",
"AZRebalance",
"AlarmNotification",
"ScheduledActions"
],
"WaitOnResourceSignals": true
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,13 @@ describe('CDK Include', () => {
);
});

test('correctly handles string arrays in policy attributes', () => {
const cfnTemplate = includeTestTemplate(stack, 'string-arrays-in-policy.json');
Template.fromStack(stack).templateMatches(
loadTestFileToJsObject('string-arrays-in-policy.json'),
);
});

test("correctly handles referencing the ingested template's resources across Stacks", () => {
// for cross-stack sharing to work, we need an App
const app = new core.App();
Expand Down
6 changes: 3 additions & 3 deletions packages/aws-cdk-lib/core/lib/helpers-internal/cfn-parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class FromCloudFormation {
}

// in all other cases, delegate to the standard mapping logic
return this.getArray(this.getString)(value);
return FromCloudFormation.getArray(FromCloudFormation.getString)(value);
}

public static getArray<T>(mapper: (arg: any) => FromCloudFormationResult<T>): (x: any) => FromCloudFormationResult<T[]> {
Expand Down Expand Up @@ -716,8 +716,8 @@ export class CfnParser {

const key = objectKeys[0];
return key === 'Ref' || key.startsWith('Fn::') ||
// special intrinsic only available in the 'Conditions' section
(this.options.context === CfnParsingContext.CONDITIONS && key === 'Condition')
// special intrinsic only available in the 'Conditions' section
(this.options.context === CfnParsingContext.CONDITIONS && key === 'Condition')
? key
: undefined;
}
Expand Down

0 comments on commit 0c2f98b

Please sign in to comment.