Skip to content

aws-cdk-lib/core: cfn-parse cannot parse CfnInclude template #32454

@mikevoets

Description

@mikevoets

Describe the bug

We have a cloudformation template for autoscaling that we import into our CDK stack with CfnInclude.

I believe that #32321 that was released in [email protected] last week broke the parsing of this template, because we now get an error when we synthesize this stack. In [email protected], the synthesization works without any errors thrown.

Regression Issue

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

Last Known Working CDK Version

2.171.0

Expected Behavior

The stack synthesization is successful and runs without errors.

Current Behavior

The stack synthesization fails with:

TypeError: Cannot read properties of undefined (reading 'getArray')
    at getStringArray (/Users/path/to/repo/node_modules/aws-cdk-lib/core/lib/helpers-internal/cfn-parse.js:1:3237)
    at ObjectParser.parse (/Users/path/to/repo/node_modules/aws-cdk-lib/core/lib/helpers-internal/cfn-parse.js:1:18595)
    at ObjectParser.parseCase (/Users/path/to/repo/node_modules/aws-cdk-lib/core/lib/helpers-internal/cfn-parse.js:1:18475)
    at parseAutoScalingRollingUpdate (/Users/path/to/repo/node_modules/aws-cdk-lib/core/lib/helpers-internal/cfn-parse.js:1:8738)
    at ObjectParser.parse (/Users/path/to/repo/node_modules/aws-cdk-lib/core/lib/helpers-internal/cfn-parse.js:1:18595)
    at ObjectParser.parseCase (/Users/path/to/repo/node_modules/aws-cdk-lib/core/lib/helpers-internal/cfn-parse.js:1:18475)
    at CfnParser.parseUpdatePolicy (/Users/path/to/repo/node_modules/aws-cdk-lib/core/lib/helpers-internal/cfn-parse.js:1:7642)
    at CfnParser.handleAttributes (/Users/path/to/repo/node_modules/aws-cdk-lib/core/lib/helpers-internal/cfn-parse.js:1:4944)
    at Function._fromCloudFormation (/Users/path/to/repo/node_modules/aws-cdk-lib/aws-autoscaling/lib/autoscaling.generated.js:1:1188)
    at CfnInclude.getOrCreateResource (/Users/path/to/repo/node_modules/aws-cdk-lib/cloudformation-include/lib/cfn-include.js:1:14510)
Subprocess exited with error 1

Reproduction Steps

Given the following code:

template.yaml

---
AWSTemplateFormatVersion: '2010-09-09'
Resources:
  AutoScalingGroup:
    Type: 'AWS::AutoScaling::AutoScalingGroup'
    Properties:
      DesiredCapacity: 1
      MaxSize: 1
      MinSize: 1
    CreationPolicy:
      ResourceSignal:
        Count: 1
        Timeout: PT10M
    UpdatePolicy:
      AutoScalingRollingUpdate:
        PauseTime: PT10M
        SuspendProcesses:
          - HealthCheck
          - ReplaceUnhealthy
          - AZRebalance
          - AlarmNotification
          - ScheduledActions
        WaitOnResourceSignals: true

app.ts

import * as cdk from 'aws-cdk-lib';
import { CfnInclude } from 'aws-cdk-lib/cloudformation-include';
import { Construct } from 'constructs';

class TestStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    new CfnInclude(this, 'Template', {
      templateFile: './template.yaml',
    });
  }
}

const app = new cdk.App();

new TestStack(app, 'TestStack', {
  env: {
    region: process.env.AWS_REGION,
    account: process.env.AWS_ACCOUNT,
  },
});

Run:

npm run cdk -- -a "npx ts-node --prefer-ts-exts app.ts" synth TestStack

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.172.0 (build 0f666c5)

Framework Version

No response

Node.js Version

v22.10.0

OS

macOS 15.1.1 (24B91)

Language

TypeScript

Language Version

TypeScript (5.7.2)

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/cloudformation-includeIssues related to the "CFN include v.20" packagebugThis issue is a bug.p0potential-regressionMarking this issue as a potential regression to be checked by team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions