-
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
fix(core): automatic cross-stack refs for CFN resources #1510
Conversation
The "toCloudFormation" method of generated CFN resources invoke "resolve" so that any lazy tokens are evaluated. This escaped the global settings set by `findTokens` which collect tokens so they can be reported as references by `StackElement.prepare`. To solve this, findTokens now accepts a function instead of an object and basically just wraps it's invocation with settings that will collect all tokens resolved within that scope. Not an ideal solution but simple enough. This was not discovered because we didn't have any tests that validated the behavior of the generated CFN resources (they are not accessible from the @aws-cdk/cdk library). We add a unit test in the IAM library to cover this case.
const ret = new Array<Token>(); | ||
|
||
const options = RESOLVE_OPTIONS.push({ collect: ret.push.bind(ret) }); | ||
try { | ||
// resolve() for side effect of calling 'preProcess', which adds to the | ||
resolve(obj, context); | ||
fn(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now assumes that resolve()
will always be called in the callback, which is not always true. Better to use resolve(fn())
, catches both cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved modulo bugfix
Thanks so much for taking the time to contribute to the AWS CDK ❤️ We will shortly assign someone to review this pull request and help get it
|
The "toCloudFormation" method of generated CFN resources invoke
"resolve" so that any lazy tokens are evaluated. This escaped the
global settings set by
findTokens
which collect tokens so theycan be reported as references by
StackElement.prepare
.To solve this, findTokens now accepts a function instead of an object
and basically just wraps it's invocation with settings that will collect
all tokens resolved within that scope. Not an ideal solution but
simple enough.
This was not discovered because we didn't have any tests that validated
the behavior of the generated CFN resources (they are not accessible
from the @aws-cdk/cdk library). We add a unit test in the IAM library to cover this case.
Pull Request Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.