-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): throw on intrinsics in CFN update and create policies (#31578
) ### Issue # (if applicable) Closes #27578, Closes #30740. ### Reason for this change `cfn-include` only allows Intrinsics in resource update and create policies to wrap primitive values. If Intrinsics are included anywhere else, `cfn-include` silently drops them. CDK's type system [does not allow](https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/core/lib/cfn-resource-policy.ts) intrinsics in resource policies unless they define a primitive value. `cfn-include` adheres to this type system and drops any resource policies that use an intrinsic to define a complex value. This is an example of a forbidden use of intrinsics: ``` "Resources": { "ResourceSignalIntrinsic": { // .... "CreationPolicy": { "ResourceSignal": { "Fn::If": [ "UseCountParameter", { "Count": { "Ref": "CountParameter" } }, 5 ] } } } } } ``` This is forbidden because an intrinsic contains the `Count` property of this policy. CFN allows this, but CDK's type system does not permit it. ### Description of changes `cfn-include` will throw if any intrinsics break the type system, instead of silently dropping them. CDK's type system is a useful constraint around these resource update / create policies because it allows constructs that modify them, like autoscaling, to not be token-aware. Tokens are not resolved at synthesis time, so it makes it impossible to modify these with simple arithmetic if they contain tokens. The CDK will never (or at least should not) generate a token that breaks this type system. Thus, the only use-case for allowing these tokens is `cfn-include`. Supporting these customers would require the CDK type system to allow these, and thus CDK L2s should handle such cases; except, for L2 customers, this use-case does not happen. Explicitly reject templates that don't conform to this. Throwing here is a breaking change, so this is under a feature flag. Additionally add a new property, `dehydratedResources` -- a list of logical IDs that `cfn-include` will not parse. Those resources still exist in the final template. This does not impact L2 users. ### Description of how you validated changes Unit testing. Manually verified that this does not impact any L2s. ### 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*
- Loading branch information
Showing
30 changed files
with
1,162 additions
and
82 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
23 changes: 23 additions & 0 deletions
23
...-lib/cloudformation-include/test/test-templates/intrinsics-create-policy-autoscaling.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"Parameters": { | ||
"MinSuccessfulInstancesPercent": { | ||
"Type": "Number" | ||
} | ||
}, | ||
"Resources": { | ||
"AutoScalingCreationPolicyIntrinsic": { | ||
"Type": "AWS::AutoScaling::AutoScalingGroup", | ||
"Properties": { | ||
"MinSize": "1", | ||
"MaxSize": "5" | ||
}, | ||
"CreationPolicy": { | ||
"AutoScalingCreationPolicy": { | ||
"MinSuccessfulInstancesPercent": { | ||
"Ref": "MinSuccessfulInstancesPercent" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.