:exclamation: 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
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
https://github.com/aws/aws-cdk/blob/cce10b1c1f0f764e39e734ad7d6c288b7ffb9da3/packages/aws-cdk-lib/cloudformation-include/lib/cfn-include.ts#L771-L775
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
Thanks @mjgoble for creating this issue. You're right that the logical id validation code is applied not only on the Resources properties only but also Conditions. This caused unexpected behaviours. As a temporary workaround, please downgrade to a previous version.
This is a regression so I'm labeling it a p0 and reverting the original PR.
Revert: https://github.com/aws/aws-cdk/pull/30695
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.