fix: Allow intrinsics in SAM Globals properties - #4683
Merged
Conversation
E3724 validates the Globals section against globals.json, but GlobalsTransform validated it without enabling intrinsic functions or intrinsic-aware type checking. Any type-constrained Globals property (e.g. Function.PermissionsBoundary, Function.Runtime) therefore rejected Ref/Fn::ImportValue/Fn::Sub that CloudFormation and the SAM translator accept and that the resource-level property already allows. Enable functions and cfn_type when validating the Globals section, matching how resource properties and Outputs values are validated. Malformed literals are still flagged, and the merged resource-level validation remains a second layer. Verified against the SAM translator (sam validate 1.165.0). aws-cloudformation#4680
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4683 +/- ##
=======================================
Coverage 94.64% 94.64%
=======================================
Files 433 433
Lines 15511 15512 +1
Branches 3011 3011
=======================================
+ Hits 14681 14682 +1
Misses 453 453
Partials 377 377
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available
Fixes #4680
Description of changes
Since #4491 the
Globalssection is validated againstglobals.jsonbyE3724(GlobalsTransform). That rule validated the section without enabling intrinsic functions or intrinsic-aware type checking, so anytype-constrained Globals property rejectedRef/Fn::ImportValue/Fn::Sub:The reporter flagged
Function.PermissionsBoundary, but it's broader — e.g.Function.Runtime: !Ref Xfailed the same way. The same intrinsic on the resource's ownPropertieswas already accepted, so only the Globals path was affected.Fix: when validating the Globals section, enable
functionsand use the intrinsic-awarecfn_type, mirroring how resource properties andOutputsvalues are validated. Malformed literals are still flagged (E3724/E3012), and the merged resource-level validation remains a second layer.Validated against the real SAM translator (
sam validate, aws-sam-translator 1.165.0): it accepts the intrinsic inGlobals.Function.PermissionsBoundaryand inGlobals.Function.Runtime; a non-intrinsic object literal is still rejected by cfn-lint's schema type check.Testing
test/unit/rules/resources/test_globals_transform.py(intrinsic inPermissionsBoundary/Runtime→ no error; non-intrinsic object → still errors).ruff,ruff format,isort,mypyclean.test/unit/rules/resources+test/unit/rules/functions(1482) and serverless integration tests pass.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.