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

Fix/adjust function nesting #417

Closed
wants to merge 2 commits into from
Closed

Conversation

dhutchison
Copy link
Collaborator

Fixes #406

This changes specifically how Fn::If is handled so the nested function rule is applied to the condition only.

@dhutchison dhutchison changed the base branch from master to develop February 10, 2025 00:57
@dhutchison dhutchison added bug Something isn't working patch A bug, doc or CICD change. labels Feb 10, 2025
Copy link

codecov bot commented Feb 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.85%. Comparing base (f1b9d72) to head (a26cb46).
Report is 120 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #417      +/-   ##
===========================================
- Coverage    95.00%   94.85%   -0.15%     
===========================================
  Files           11       12       +1     
  Lines          760      856      +96     
  Branches       155      161       +6     
===========================================
+ Hits           722      812      +90     
- Misses          21       24       +3     
- Partials        17       20       +3     
Flag Coverage Δ
unit 94.85% <100.00%> (-0.15%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +399 to +413
if key == "Fn::If":
# Need a special case for this one as the first parameter uses
# different allowed function rules than the other two parameters.
# There is probably a cleaner way to do this!
value = [
# the condition function
self.resolve_values(value[0], functions.ALLOWED_FUNCTIONS[key]),
self.resolve_values(value[1], functions.INTRINSICS),
self.resolve_values(value[2], functions.INTRINSICS),
]
else:
value = self.resolve_values(
value,
functions.ALLOWED_FUNCTIONS[key],
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhutchison Do we need a code change for this? It seems like just adding transform and split to be allowed nested under If would be the better solution?

The allowed functions list came from the AWS docs and unfortunately they are VERY incorrect. People have opened up plenty of issues over the years with working AWS provided templates that go against what AWS docs state is allowed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - I was going on the assumption that the docs were actually correct and only applied to the condition part.

If that's not right then yeah that would be a simpler solution. I think ideally we wouldn't be checking functions at all and saying to rely on a linter but don't know off the top of my head if cfn-lint would catch it (I'll check when I'm back).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean its a pretty good point. The Allowed functions was hard to implement and costly to maintain. I think 90% of issues opened are about allowed function error on a template that was provided by AWS and deploys fine.

I guess the worse case is you implement a nested function that doesn't work? Unit test it but it fails to deploy. I have done a lot of Cloudformation but not sure I ever ran into that issue. Maybe once or twice.

I think I will open an MR that tears out the allowed functions feature and we can look it over.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sounds like a plan. I can't say I remember seeing any cases myself either

@dhutchison
Copy link
Collaborator Author

Closing this as superseded by removing the checks entirely in #422

@dhutchison dhutchison closed this Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working patch A bug, doc or CICD change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow Fn::Split and Fn::Transform to be nested within Fn::If
2 participants