Skip to content

❗ NOTICE (cloudformation-include): RuntimeError: Invalid logical ID override: 'my_condition'. It must only contain alphanumeric characters. overrideLogicalId validation causing CfnInclude to error on Condition logical Id #30669

@mjgoble

Description

@mjgoble

Please add your +1 👍 to let us know you have encountered this

Status: RESOLVED

Fixed in v2.147.2

Overview:

New synth time logical Id checks for CloudFormation Resources are also being applied to CloudFormation Conditions. Resource ID validation is more strict that Condition ID validation, causing valid Conditions to be caught by the new validation, and errors to be thrown.

Specifically, this bug affects cloudformation-include. When trying to cfnInclude a CloudFormation template that has defined Conditions using non-alphanumeric characters, e.g. snake case my_condition, will now throw an error.

Complete Error Message:

RuntimeError: Invalid logical ID override: 'my_condition'. It must only contain alphanumeric characters.

Workaround:

Pin the version of aws-cdk-lib to 2.146.0.

Solution:

Revert breaking PR.

Related Issues:

Original report

Describe the bug

The following PR #29708 introduced validation for overrideLogicalId

This has caused an issue with cloudformation-include when trying to cfnInclude a cloudformation template that has defined Conditions using non-alphanumeric characters, e.g. snake case my_condition

Cloudformation include by default preserves the logical Id that is defined in the cloudformation template. This is done in part by using the overrideLogicalId function to ensure the logical id of the resource is not changed during the cdk synth

private overrideLogicalIdIfNeeded(element: core.CfnElement, id: string): void {
if (this.preserveLogicalIds) {
element.overrideLogicalId(id);
}
}

Now due to the new validation on overrideLogicalId - Conditions cannot be defined as non-alphanumeric despite them never actually being deployed as resources in Cloudformation

Expected Behavior

Stack synth completes successfully, logical Ids defined in the included cloudformation template is preserved, including the snake case Condition logical Ids

Cloudformation deploy succeeds even despite having non-alphanumeric logical Ids defined for Conditions

Current Behavior

Stack synth fails with a Runtime Error
RuntimeError: Invalid logical ID override: 'my_condition'. It must only contain alphanumeric characters.

Reproduction Steps

cfn_include a cloudformation template that defines conditions using snake case logical id, e.g. my_condition

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.147.1

Framework Version

No response

Node.js Version

20.5.0

OS

Linux

Language

Python

Language Version

Python (3.12.3)

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.management/trackingIssues that track a subject or multiple issuesp0

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions