Skip to content

Commit ce76a56

Browse files
authored
fix(cloudformation-include): aws::novalue type validation error for non-string properties (#35425)
### Issue # (if applicable)   Closes #18420   ### Reason for this change   When we try to include a Cloudformation template that uses `{ Ref: 'AWS::NoValue' }` for a boolean-typed property, we get an error like:   `Error: Expected 'true' or 'false' for boolean value, got: '${Token[AWS.NoValue.7]}'`   This problem occurs because the CFN parser uses the `Aws.NO_VALUE` constant (which is defined as a string). CDK sees a string value for a boolean property and attempts to convert the string to boolean values. This results in the error we see above.   ### Description of changes   This change modifies the CFN parser in cloudformation-include to return a token value instead of a direct string constant for AWS::NoValue references. This makes it an IResolvable token that works with any property type. The parser then, in turn, ignores the default error being thrown whenever a non-string is passed.   ### Describe any new or updated permissions being added   No new IAM permissions required   ### Description of how you validated changes   A unit test is added to check if an IResolvable token is returned for AWS::NoValue. An integration test deploys a Cloudformation stack with `AWS::NoValue` in a boolean property. Both tests pass. An assertion isn't needed here since the deployment of the infrastructure indicates that the test succeeded.   ### 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*
1 parent 2de6e39 commit ce76a56

File tree

11 files changed

+789
-1
lines changed

11 files changed

+789
-1
lines changed

packages/@aws-cdk-testing/framework-integ/test/cloudformation-include/test/integ.novalue-nonstring.js.snapshot/CfnIncludeNoValueBooleanTestDefaultTestDeployAssert806459F3.assets.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/cloudformation-include/test/integ.novalue-nonstring.js.snapshot/CfnIncludeNoValueBooleanTestDefaultTestDeployAssert806459F3.template.json

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/cloudformation-include/test/integ.novalue-nonstring.js.snapshot/cdk.out

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/cloudformation-include/test/integ.novalue-nonstring.js.snapshot/integ-cfninclude-novalue-boolean.assets.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"AWSTemplateFormatVersion": "2010-09-09",
3+
"Resources": {
4+
"TestBucket": {
5+
"Type": "AWS::S3::Bucket",
6+
"Properties": {
7+
"BucketName": "test-novalue-boolean-bucket",
8+
"ObjectLockEnabled": {
9+
"Ref": "AWS::NoValue"
10+
}
11+
}
12+
}
13+
},
14+
"Outputs": {
15+
"BucketName": {
16+
"Value": {
17+
"Ref": "TestBucket"
18+
}
19+
}
20+
},
21+
"Parameters": {
22+
"BootstrapVersion": {
23+
"Type": "AWS::SSM::Parameter::Value<String>",
24+
"Default": "/cdk-bootstrap/hnb659fds/version",
25+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
26+
}
27+
},
28+
"Rules": {
29+
"CheckBootstrapVersion": {
30+
"Assertions": [
31+
{
32+
"Assert": {
33+
"Fn::Not": [
34+
{
35+
"Fn::Contains": [
36+
[
37+
"1",
38+
"2",
39+
"3",
40+
"4",
41+
"5"
42+
],
43+
{
44+
"Ref": "BootstrapVersion"
45+
}
46+
]
47+
}
48+
]
49+
},
50+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
51+
}
52+
]
53+
}
54+
}
55+
}

packages/@aws-cdk-testing/framework-integ/test/cloudformation-include/test/integ.novalue-nonstring.js.snapshot/integ.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)