Assign tags to all resources of a nested stack

1k Views Asked by At

I'm trying to make use of NestedStack but I can't find the way to propagate the tags to all the resources of the stack as the NestedStack construct does not have the field tags as it's the case in the construct Stack.

So, for example, I can't run

const stack = cdk.Stack.of(scope);

for (let key in props.tags) {
    cdk.Tags.of(scope).add(key, tags[key], {
        applyToLaunchedInstances: false,
        excludeResourceTypes: ["AWS::EC2::EIP"]
    })
}

Error Message

Property 'tags' does not exist on type 'ekstackprops'.ts(2339)

Where ekstackprops extends NestedStackProps.

1

There are 1 best solutions below

0
fedonev On

If you add tags to a scope that includes a NestedStack construct, the CDK propagates the tags down to the nested stack's child resources at synth-time.

For instance, if MyStack contains a MyNestedStack, which in turn has a MyNestedLambda construct, the following will add a tag to all three:

declare const MyStack: cdk.Stack // includes a MyNestedStack construct

cdk.Tags.of(MyStack).add('TagName', 'TaggyMcTagFace');