Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cdk migrate: nested shortform functions fail to migrate #30810

Open
Shwaring opened this issue Jul 10, 2024 · 8 comments
Open

cdk migrate: nested shortform functions fail to migrate #30810

Shwaring opened this issue Jul 10, 2024 · 8 comments
Labels
@aws-cdk/aws-cloudformation Related to AWS CloudFormation bug This issue is a bug. cli Issues related to the CDK CLI effort/medium Medium work item – several days of effort p1

Comments

@Shwaring
Copy link

Describe the bug

Cloudformation intrinisc finctions have short froms and long forms. When functions using the short form you get the unhelpful error message migrate failed for : <stackname> could not be generated because <element>: untagged and internally tagged enums do not support enum input at line 141 column 25
I believe this error message is unrelated and is simply a fallback error for some reason.
The following snippet shows that converting to long form functions migrates correctly but the nested shortform functions fail.

Expected Behavior

Generate a valid CDK stack

Current Behavior

migrate fails with migrate failed for : <stackname> could not be generated because <element>: untagged and internally tagged enums do not support enum input at line <line> column <column> error

Reproduction Steps

run cdk migrate --stack-name my-stack --language typescript --from-path <template> --output-path <path for output> using

AWSTemplateFormatVersion: "2010-09-09"
Description: ABS Insights Aurora Postgres

Conditions:
  cUseDBSnapshot: 
    Fn::Not: 
      Fn::Equals: 
        - Ref: pDBSnapshotIdentifier
        - ""
  cAddCollectServicesIngress: 
    Fn::Not: 
      Fn::Equals: [Ref: pCollectServicesIP , ""]
  cAddCollectServices2Ingress: !Not [!Equals [!Ref pCollectServicesIP2 , ""]]
  cAddCollectServices3Ingress: !Not [!Equals [!Ref pCollectServicesIP3 , ""]]
  cAddCollectServices4Ingress: !Not [!Equals [!Ref pCollectServicesIP4 , ""]]
  cAddCollectServices5Ingress: !Not [!Equals [!Ref pCollectServicesIP5 , ""]]
  cArcGISFirstIPIngress: !Not [!Equals [!Ref pArcGISFirstIP , ""]]
  cArcGISSecondIPIngress: !Not [!Equals [!Ref pArcGISSecondIP , ""]]
  cCreateAdminSecret: !Not [!Condition cUseDBSnapshot]

Possible Solution

Current workaround is to expand these functions into the long forms

Additional Information/Context

No response

CDK CLI Version

2.145.0

Framework Version

No response

Node.js Version

v20.14.0

OS

linux

Language

TypeScript

Language Version

No response

Other information

No response

@Shwaring Shwaring added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 10, 2024
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Jul 10, 2024
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Jul 11, 2024

Reproducible. Looking at the code for cdk migrate:

Unsure if this is root cause. Needs more investigation.

@ashishdhingra ashishdhingra added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jul 11, 2024
@ashishdhingra ashishdhingra self-assigned this Jul 11, 2024
@Shwaring
Copy link
Author

Hey, not sure if this is what you are implying, but the ref function long form is not supposed to have the 'Fn::' prefix see docs
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html

@ashishdhingra
Copy link
Contributor

ashishdhingra commented Jul 11, 2024

Hey, not sure if this is what you are implying, but the ref function long form is not supposed to have the 'Fn::' prefix see docs https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html

@Shwaring Thanks for sharing the link. I just added my findings in #30810 (comment). Is it possible to share minimal almost complete template? The error might be thrown my yaml package (not entirely sure though). I also mentioned in my previous comment that For tags Ref and Condition, it doesn't add Fn:: prefix.

@Shwaring
Copy link
Author

AWSTemplateFormatVersion: 2010-09-09
Description: example

Parameters:

  pExample:
    Type: String
    Description: example paramater
    Default: param
Conditions:
  cNotBrokenCondition: 
    Fn::Not: 
      Fn::Equals: 
        - Ref: pExample
        - ""
  cAlsoNotBrokenCondition: 
    Fn::Not: 
      Fn::Equals: [Ref: pExample , ""]
  cBrokenCondition: !Not [!Equals [!Ref pExample , ""]]
Resources:

@ashishdhingra
Copy link
Contributor

@Shwaring Thanks for providing the sample template. Running cdk migrate on this template gives below error:

This command is an experimental feature.
 ❌  Migrate failed for `my-stack`: MyStackStack could not be generated because Conditions.cBrokenCondition[0]: untagged and internally tagged enums do not support enum input at line 19 column 27

MyStackStack could not be generated because Conditions.cBrokenCondition[0]: untagged and internally tagged enums do not support enum input at line 19 column 27

Upon searching through existing issues, it appears that this is similar to #29181. Please review.

Thanks,
Ashish

@ashishdhingra ashishdhingra added p1 @aws-cdk/aws-cloudformation Related to AWS CloudFormation toolkit/migrate Related to cdk migrate cli Issues related to the CDK CLI and removed @aws-cdk/aws-lambda Related to AWS Lambda p2 labels Jul 12, 2024
@Shwaring
Copy link
Author

Yep I believe that is the same issue

@ashishdhingra
Copy link
Contributor

Yep I believe that is the same issue

@Shwaring Thanks for the confirmation. I will bring this and other issue to team's attention. Most likely would close this one since team might be tracking other issue internally.

@Shwaring
Copy link
Author

Shwaring commented Aug 6, 2024

Has any progress been made on this issue? I am planning on migrate another set of CFN templates soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cloudformation Related to AWS CloudFormation bug This issue is a bug. cli Issues related to the CDK CLI effort/medium Medium work item – several days of effort p1
Projects
None yet
Development

No branches or pull requests

3 participants