-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
(aws-core): Tags do not persist on constructs imported from another project (outside current dir) #18914
Comments
I would like to add that it is not isolated to a VPC. Any custom construct being used as library outside the main project's directory will have its tags removed in the final cfn template. One work around is to copy the output of npm run build of the library folder and copy it to the main project folder and use that as the current library. Also tested using symbolic link. It doesn't work either. |
I was able to reproduce this and i've made a repo with the simplest reproduction. I've also created a couple of tests in that repo that validate this problem. |
When construct libraries are purposely symlinked (as opposed of collectively `npm install`ed), depending on how this is done they may end up with multiple copies of `aws-cdk-lib`. If that happens, Aspects from a different `aws-cdk-lib` copy than the one providing `App` will not be applied. The reason is the use of `Symbol('...')` instead of `Symbol.for('...')` to keep the list of aspects on the construct object. - The first version creates a unique symbol per library, while adding a naming hint. - The second version deduplicates: all symbols with the same naming hint will receive the same symbol. The second version is necessary to make sure that different copies of the `aws-cdk-lib` library store their aspects under the same key. Fixes #18921, #18778, #19390, #18914
|
What is the problem?
Tags are not present on custom constructs that are imported from another project (outside of current project dir).
Consider the following file structure:
I am importing a custom construct from
external-project/lib/vpc.ts
intomain-project/lib/one-internal-one-external.ts
, then runningcdk synth
frommain-project/
. This works without error however the generated CFN template does not include any tags on the externally imported resource. The internally imported custom constructs (e.g.main-project/lib/vpc.ts
) are fine as they include the expected tags in the template.Reproduction Steps
Update: check out this repo https://github.com/ryparker/aws-cdk-external-construct-tags
Create 2 directories. cdk-test-lib and cdk-test-proj
Go to cdk-test-lib and execute cdk init lib --language=typescript
Once done, got to lib folder (it should contain index.ts) then create vpc.ts
In vpc.ts, add this
Once done, go to the root dir of cdk-test-lib and execute npm run build.
Navigate to cdk-test-proj, execute cdk init app --language=typescript and edit bin/cdk-test-proj.ts
What did you expect to happen?
I expect that regardless of the location of the library file, the synthesized template should be the same and have its subnets tagged. Subnets should have tag.
e.g. (except from template synthesized from above code)
What actually happened?
Subnets don't have any tags. Even the VPC wasn't tagged when using library files outside the project directory
CDK CLI Version
2.12.0 (build c9786db)
Framework Version
No response
Node.js Version
v14.18.2
OS
Amazon Linux 2 (ami-02a45d709a415958a)
Language
Typescript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: