-
Notifications
You must be signed in to change notification settings - Fork 4k
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
(core): exportValue doesn't respect overridelogicalId #14335
Comments
Hey @liamfd, Thank you for reporting this, this does look concerning. If you want to implement and submit a fix yourself, that would be welcomed, otherwise someone from the dev team will take a look as soon as time permits. If you want to increase visibility with 👍 to the issue we may bump it up on our priority list. 😸 😷 |
I don't think this is something that we can improve upon. When you call aws-cdk/packages/@aws-cdk/core/lib/stack.ts Lines 930 to 932 in 6f4aba8
We could potentially add a validation that will throw an error if the ids pre/post synthesis are different with instructions on how to fix. Not sure if you have any other thoughts @rix0rrr |
When using `Stack.exportValue` to manually create a CloudFormation export, the logicalId of the referenced resource is used to generate the logicalId of the `CfnExport`. Because `exportValue` creates a `CfnExport` _and_ returns an `importValue` it needs to _resolve_ the logicalId at call time. If the user later overrides the logicalId of the referenced resource, that override is reflected in the export/import that was created earlier. There doesn't seem to be a way to solve this without incurring a breaking change so this PR attempts to smooth a rough edge by "locking" the `logicalId` when `exportValue` is called. If the user attempts to override the id _after_ that point, an error message will be thrown closes #14335 ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
If we create a stack like:
If we synth that, we get this in
Producer
:As you can see, both of these have the same value, but different names.
Consumer
uses the output with the overridden ID:Some other cases:
overrideLogicalId
we get onlyExportsOutputFnGetAttMyBucketF68F3FF0Arn0F7E8E58
in both stacksConsumer
we get only theExportsOutputFnGetAttMyBucketF68F3FF0Arn0F7E8E58
Output inProducer
exportValue
after theoverrideLogicalId
we get onlyExportsOutputFnGetAttOVERRIDELOGICALIDArn49941B8D
in both stacksSo, basically, it seems like
exportValue
creates the name for the initial logicalId and that doesn't change when it gets overridden. References in other stacks will create Outputs based on the new logicalId, ignoring the ones created byexportValue
.I believe this makes it a bit harder to use
exportValue
to avoid the deadly embrace, because the Outputs it generates in this case aren't the ones imported in a dependent's stack.Reproduction Steps
I just created a file with the above and passed it to a
cdk synth --app 'yarn babel-node my-file.ts'
.What did you expect to happen?
I'd expect just a single Output.
What actually happened?
Two Outputs get created,
Consumer
does not reference the Output created withcreateExports
, it references a lazily created Output that includes the overridden logicalId in its name.Environment
Other
It's worth noting that this is pretty easy to work around - you just have to call
exportValue
afteroverrideLogicalId
.This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: