-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
core: CfnParser can't correctly parse conditional Tags #27594
Closed
jaredlundell opened this issue
Oct 18, 2023
· 2 comments
· Fixed by #30515 or softwaremill/tapir#4137 · May be fixed by NOUIY/aws-solutions-constructs#133, NOUIY/aws-solutions-constructs#134 or ajobayer/aws-secure-environment-accelerator#4
Closed
core: CfnParser can't correctly parse conditional Tags #27594
jaredlundell opened this issue
Oct 18, 2023
· 2 comments
· Fixed by #30515 or softwaremill/tapir#4137 · May be fixed by NOUIY/aws-solutions-constructs#133, NOUIY/aws-solutions-constructs#134 or ajobayer/aws-secure-environment-accelerator#4
Labels
Comments
jaredlundell
added
bug
This issue is a bug.
needs-triage
This issue or PR still needs to be triaged.
labels
Oct 18, 2023
peterwoodworth
added
p1
and removed
needs-triage
This issue or PR still needs to be triaged.
labels
Oct 18, 2023
Thanks for the bug report and deep dive into the code @jaredlundell, since you seem to be familiar with it would you be willing to help us by submitting a PR? |
1 task
mergify bot
pushed a commit
that referenced
this issue
Sep 10, 2024
### Issue # (if applicable) Closes #27594. ### Reason for this change Templates that use intrinsics in resource Tags cannot be used with CFN Include. ### Description of changes Modifed the CFN Parser to not choke on Intrinsics found in resource Tags. ### Description of how you validated changes Unit tests. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Comments on closed issues and PRs are hard for our team to see. |
xazhao
pushed a commit
to xazhao/aws-cdk
that referenced
this issue
Sep 12, 2024
) ### Issue # (if applicable) Closes aws#27594. ### Reason for this change Templates that use intrinsics in resource Tags cannot be used with CFN Include. ### Description of changes Modifed the CFN Parser to not choke on Intrinsics found in resource Tags. ### Description of how you validated changes Unit tests. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Describe the bug
The CfnParser class (used by the CfnInclude construct) cannot correctly parse Tag declarations that conditionally include tags. Using intrinsic functions inside the
Key
orValue
of a Tag is fine, but if you try to declare a tag using a top-levelFn::If
(which is allowed by CloudFormation), parsing using CfnParser fails.Expected Behavior
CfnParser should be able to correctly parse Tag declarations that use
Fn::If
.Current Behavior
Tag declarations that use top-level
Fn::If
get turned into an empty{}
by CfnParser, which causes failure during synthesis when{}
is rejected as an invalid Tag by validateCfnTag()The error message looks like this:
Reproduction Steps
Create a CFN template with a resource containing a tag specification that looks like this:
If you try to include that template into a CDK application using CfnInclude, it results in a synthesis failure.
Possible Solution
There are two places that are causing problems here. The first is the FromCloudFormation.getCfnTag() function from
cfn-parse.ts
. It assumes that a parsed tag will always be an object withKey
andValue
properties. Tags declared usingFn::If
get turned into anIResolvable
object instead. Addingif (isResolvableObject(tag)) { return tag }
togetCfnTag()
should solve that part of the problem.The second problem is the cfnTagToCloudFormation() function from
runtime.ts
. It also assumes that tags are always objects withKey
andValue
properties. My recommended solution here would be to addif (!canInspect(x)) { return x; }
, similar to what the listMapper and hashMapper functions do.Additional Information/Context
No response
CDK CLI Version
2.94
Framework Version
No response
Node.js Version
18.16.0
OS
Linux
Language
TypeScript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: