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: Cannot add metadata to NestedStack when including template #29853

Open
peermuellerxw opened this issue Apr 16, 2024 · 1 comment
Open
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

@peermuellerxw
Copy link

peermuellerxw commented Apr 16, 2024

Describe the bug

When I try to add metadata to a stack that is created with CfnInclude I get the following error:

    at mergeObjectsWithoutDuplicates (/.../cfninclude-example/node_modules/aws-cdk-lib/core/lib/stack.js:2:854)

This seems confusing as I was trying to add a different metadata key/value pair via cdk.

Expected Behavior

I expected the templates to synthesize and the nested stack to have all metadata values

Current Behavior

No template is synthesized

Reproduction Steps

The template:

AWSTemplateFormatVersion: 2010-09-09
Metadata:
  some-data: "some-value"

Resources:
  MyBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: new-bucket

The CDK app:

#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import path = require('path');
import { CfnInclude } from 'aws-cdk-lib/cloudformation-include';

const app = new cdk.App();



class ParentStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);


    new CfnincludeExampleStack(this, 'CfnincludeExampleStack');
  }
}

class CfnincludeExampleStack extends cdk.NestedStack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const template = new CfnInclude(this, 'CfnincludeTemplate', {
      templateFile: path.join('./include-stack.yaml'),
    });

    this.addMetadata('more-data', 'more-value');

    //This seems to work, but it's not the right way to do it
    //(Stack.of(template.stack).node.defaultChild as CfnStack).stack.addMetadata('more-data', 'more-value');
  }
}

new ParentStack(app, 'ParentStack');




Possible Solution

//This seems to work, but it's not the right way to do it
(Stack.of(template.stack).node.defaultChild as CfnStack).stack.addMetadata('more-data', 'more-value');

Additional Information/Context

This only happens with nested stacks.

CDK CLI Version

2.131.0 (build 92b912d)

Framework Version

No response

Node.js Version

v20.10.0

OS

MacOs Sonoma

Language

TypeScript

Language Version

5.3.3

Other information

No response

@peermuellerxw peermuellerxw added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 16, 2024
@github-actions github-actions bot added the @aws-cdk/cloudformation-include Issues related to the "CFN include v.20" package label Apr 16, 2024
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Apr 16, 2024
@khushail khushail self-assigned this Apr 16, 2024
@khushail
Copy link
Contributor

khushail commented Apr 29, 2024

thanks for reporting this bug with nested stack metadata addition @peermuellerxw . I also see the same error msg as reported by you. Although I am looking for a workaround , suggested commented solution shared by you does not work for me. will share if I get any updates on other workaround.

@khushail khushail added p2 effort/small Small work item – less than a day of effort and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Apr 29, 2024
@khushail khushail removed their assignment Apr 29, 2024
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

No branches or pull requests

2 participants