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

(CfnInclude): Nested stack parameters must be strings #15092

Closed
MasonHM opened this issue Jun 11, 2021 · 2 comments · Fixed by #15098
Closed

(CfnInclude): Nested stack parameters must be strings #15092

MasonHM opened this issue Jun 11, 2021 · 2 comments · Fixed by #15098
Assignees
Labels
@aws-cdk/cloudformation-include Issues related to the "CFN include v.20" package bug This issue is a bug. effort/small Small work item – less than a day of effort p2

Comments

@MasonHM
Copy link

MasonHM commented Jun 11, 2021

When using the CfnInclude module to import a nested stack with a 'Number' parameter and the parent stack provides an unquoted number, CDK throws an error saying:

Error: Resolution error: Supplied properties not correct for "CfnStackProps"
  parameters: element 'Number': 60 should be a string.

Changing the parameter to a quoted string (60 --> '60') in the parent template fixes the problem. In my case, this would mean changing the parameter format in dozens of locations, so I'd rather have CDK support number parameters the way I expect.

CloudFormation documentation says:

AWS CloudFormation validates the parameter value as a number; however, when you use the parameter elsewhere in your template (for example, by using the Ref intrinsic function), the parameter value becomes a string.

This problem may be related to #744.

Reproduction Steps

parent-stack.yaml:

AWSTemplateFormatVersion: '2010-09-09'

Resources:
  NestedStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: 'https://s3.amazonaws.com/masonme-cdk-test/templates/nested-stack.yaml'
      Parameters:
        Number: 60

nested-stack.yaml:

AWSTemplateFormatVersion: '2010-09-09'

Parameters:
  Number:
    Type: Number

Resources:
  S3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: 'testbucket1234unique'

bin/min-repro-int-param.ts:

#!/usr/bin/env node
import { App, Stack } from '@aws-cdk/core';
import { CfnInclude } from '@aws-cdk/cloudformation-include';

class NestedStackTest extends Stack {
  constructor(scope: App, id: string) {
    super(scope, id);

    const cfnTemplate = new CfnInclude(this, 'template', {
      templateFile: 'parent-stack.yaml',
      loadNestedStacks: {
        'NestedStack': {
          templateFile: 'nested-stack.yaml'
        }
      }
    });
  }
}

const app = new App();
new NestedStackTest(app, 'NestedStackTest');

What did you expect to happen?

I expected cdk synth to work correctly and generate the CloudFormation.

Expected output:

[masonme@f45c89b36d13] $ cdk synth
AWSTemplateFormatVersion: "2010-09-09"
Resources:
  NestedStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL:
        Fn::Join:
          - ""
          - - https://s3.us-east-2.
            - Ref: AWS::URLSuffix
            - /
            - Ref: AssetParameters866b547d9ca7cbf354b8fa729a93a314c8b525c1883336492117d99e62eb7a26S3Bucket0D4E156C
            - /
            - Fn::Select:
                - 0
                - Fn::Split:
                    - "||"
                    - Ref: AssetParameters866b547d9ca7cbf354b8fa729a93a314c8b525c1883336492117d99e62eb7a26S3VersionKeyC690772D
            - Fn::Select:
                - 1
                - Fn::Split:
                    - "||"
                    - Ref: AssetParameters866b547d9ca7cbf354b8fa729a93a314c8b525c1883336492117d99e62eb7a26S3VersionKeyC690772D
      Parameters:
        Number: "60"
Parameters:
  AssetParameters866b547d9ca7cbf354b8fa729a93a314c8b525c1883336492117d99e62eb7a26S3Bucket0D4E156C:
    Type: String
    Description: S3 bucket for asset "866b547d9ca7cbf354b8fa729a93a314c8b525c1883336492117d99e62eb7a26"
  AssetParameters866b547d9ca7cbf354b8fa729a93a314c8b525c1883336492117d99e62eb7a26S3VersionKeyC690772D:
    Type: String
    Description: S3 key for asset version "866b547d9ca7cbf354b8fa729a93a314c8b525c1883336492117d99e62eb7a26"
  AssetParameters866b547d9ca7cbf354b8fa729a93a314c8b525c1883336492117d99e62eb7a26ArtifactHashF5304F6F:
    Type: String
    Description: Artifact hash for asset "866b547d9ca7cbf354b8fa729a93a314c8b525c1883336492117d99e62eb7a26"

What actually happened?

cdk synth exited with an error.

Actual output:

[masonme@f45c89b36d13] $ cdk synth

/Users/masonme/cdk-migration-test/node_modules/@aws-cdk/core/lib/runtime.ts:141
    return this.errorMessage + (childMessages.length ? `\n  ${childMessages.replace(/\n/g, '\n  ')}` : '');
            ^
Error: Resolution error: Supplied properties not correct for "CfnStackProps"
  parameters: element 'Number': 60 should be a string.
    at ValidationResult.assertSuccess (/Users/masonme/cdk-migration-test/node_modules/@aws-cdk/core/lib/runtime.ts:141:13)
    at cfnStackPropsToCloudFormation (/Users/masonme/cdk-migration-test/node_modules/@aws-cdk/core/lib/cloudformation.generated.ts:1237:40)
    at CfnStack.renderProperties (/Users/masonme/cdk-migration-test/node_modules/@aws-cdk/core/lib/cloudformation.generated.ts:1367:16)
    at PostResolveToken.ret.Resources [as processor] (/Users/masonme/cdk-migration-test/node_modules/@aws-cdk/core/lib/cfn-resource.ts:324:40)
    at PostResolveToken.postProcess (/Users/masonme/cdk-migration-test/node_modules/@aws-cdk/core/lib/util.ts:92:17)
    at Object.postProcess (/Users/masonme/cdk-migration-test/node_modules/@aws-cdk/core/lib/private/resolve.ts:115:78)
    at DefaultTokenResolver.resolveToken (/Users/masonme/cdk-migration-test/node_modules/@aws-cdk/core/lib/resolvable.ts:149:32)
    at resolve (/Users/masonme/cdk-migration-test/node_modules/@aws-cdk/core/lib/private/resolve.ts:202:51)
    at Object.resolve (/Users/masonme/cdk-migration-test/node_modules/@aws-cdk/core/lib/private/resolve.ts:112:77)
    at resolve (/Users/masonme/cdk-migration-test/node_modules/@aws-cdk/core/lib/private/resolve.ts:220:47)
Subprocess exited with error 1

Environment

  • CDK CLI Version : 1.103.0 (build bc13a66)
  • Framework Version: Not sure what this means
  • Node.js Version: v14.15.4
  • OS : OSX 10.14.6
  • Language (Version): TypeScript (Version 4.1.5)

Other

This may be related to #744, but I'm not sure.


This is 🐛 Bug Report

@MasonHM MasonHM added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 11, 2021
@skinny85
Copy link
Contributor

Thanks for reporting @MasonHM, confirming I was able to reproduce the error. Working on a fix.

@skinny85 skinny85 self-assigned this Jun 11, 2021
@skinny85 skinny85 added @aws-cdk/cloudformation-include Issues related to the "CFN include v.20" package effort/small Small work item – less than a day of effort p2 and removed needs-triage This issue or PR still needs to be triaged. labels Jun 11, 2021
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Jun 11, 2021
When we include a NestedStack when creating a CfnInclude instance,
the conversion of the Parameters property of the AWS::CloudFormation::Stack resource is performed manually
(because of the eventuality that one of those Parameters was also requested to be removed when including the nested stack).
In that manual conversion, we did not correctly convert the values to strings,
which is what the underlying CfnStack class expects.
And so, if the parent stack passed a non-string primitive value to a nested stack Parameter,
like a number or boolean,
including the nested stack would fail with a validation exception.

Fixes aws#15092
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Jun 14, 2021
When we include a NestedStack when creating a CfnInclude instance,
the conversion of the Parameters property of the AWS::CloudFormation::Stack resource is performed manually
(because of the eventuality that one of those Parameters was also requested to be removed when including the nested stack).
In that manual conversion, we did not correctly convert the values to strings,
which is what the underlying CfnStack class expects.
And so, if the parent stack passed a non-string primitive value to a nested stack Parameter,
like a number or boolean,
including the nested stack would fail with a validation exception.

Fixes aws#15092
@MasonHM MasonHM changed the title (CfnInclude): Nested stack parameters can't be Number (CfnInclude): Nested stack parameters must be strings Jun 14, 2021
@mergify mergify bot closed this as completed in #15098 Jun 14, 2021
mergify bot pushed a commit that referenced this issue Jun 14, 2021
…gs (#15098)

When we include a NestedStack when creating a CfnInclude instance,
the conversion of the Parameters property of the AWS::CloudFormation::Stack resource is performed manually
(because of the eventuality that one of those Parameters was also requested to be removed when including the nested stack).
In that manual conversion, we did not correctly convert the values to strings,
which is what the underlying CfnStack class expects.
And so, if the parent stack passed a non-string primitive value to a nested stack Parameter,
like a number or boolean, including the nested stack would fail with a validation exception.

Fixes #15092

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

hollanddd pushed a commit to hollanddd/aws-cdk that referenced this issue Aug 26, 2021
…gs (aws#15098)

When we include a NestedStack when creating a CfnInclude instance,
the conversion of the Parameters property of the AWS::CloudFormation::Stack resource is performed manually
(because of the eventuality that one of those Parameters was also requested to be removed when including the nested stack).
In that manual conversion, we did not correctly convert the values to strings,
which is what the underlying CfnStack class expects.
And so, if the parent stack passed a non-string primitive value to a nested stack Parameter,
like a number or boolean, including the nested stack would fail with a validation exception.

Fixes aws#15092

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/cloudformation-include Issues related to the "CFN include v.20" package bug This issue is a bug. effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants