aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.5k stars 3.84k forks source link

(cfn-include): AWS::NoValue fails for a boolean-typed property #18420

Open skinny85 opened 2 years ago

skinny85 commented 2 years ago

What is the problem?

When trying to include a template with the cloudformation-include module that uses { Ref: 'AWS::NoValue' } for a boolean-typed property, you get an error like:

Error: Expected 'true' or 'false' for boolean value, got: '${Token[AWS.NoValue.7]}'

Reproduction Steps

Here's a minimal template showing the issue:

AWSTemplateFormatVersion: "2010-09-09"
Resources:
  CloudFrontDistribution:
    Type: "AWS::CloudFront::Distribution"
    Properties:
      DistributionConfig:
        Enabled: "true"
        ViewerCertificate:
          CloudFrontDefaultCertificate:
            Ref: "AWS::NoValue"
skinny85 commented 2 years ago

The problem is here. Our CFN parser uses the built-in Aws.NO_VALUE constant, which erroneously assumes that AWS::NoValue can only be used for a string, but of course NoValue can be used for any type, including complex types.

So, the solution is to change this line to use an IResolvable instead of Aws.NO_VALUE, and this way we'll never get into this branch of the getBoolean() function, and everything will work great.

github-actions[bot] commented 1 year ago

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

skinny85 commented 1 year ago

@comcalvi should I post a fix for this? It should be easy, as I explained in this comment.