-
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
fix: stack.partition is never scoped #1763
Conversation
A fully specified ARN can now be used in a different stack without leading to a Fn::ImportValue (used to be that we incurrend an ImportValue because of the Partition, but that is silly because the variable is known anyway). BREAKING CHANGE: 'Aws' class returns unscoped Tokens, introduce a new class 'ScopedAws' which returns scoped Tokens.
} | ||
|
||
public static get stackId(): string { | ||
return new AwsStackId(undefined).toString(); |
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.
What’s the benefit of having the scope argument in all these ctors?
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.
So the consumer is being forced to make a conscious choice about making it scoped or nonscoped. You can't just forget to supply the constructor arg.
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.
But what is the meaning of a scoped AwsRegion? Moreover why do we even need those as separate classes? Aren’t then static properties sufficient?
I feel I am missing something :-)
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.
It is fundamentally correct to treat region as scoped because it depends on the providing stack, but practically useless because in the only situation in which you would return the value and can usefully use it, it would be the same as the consumer's AWS::Region.
So yeah, I'll change 😊
@@ -40,10 +83,6 @@ export class Aws { | |||
public get stackName(): string { | |||
return new AwsStackName(this.scope).toString(); |
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.
How does it make sense to export { AWS::StackName }? Or is it just to discover that things come from a different stack?
Something is oddd
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.
It could make sense:
Properties:
Thing:
Type: AWS::Thing::Thing
Outputs:
ThingStack:
Value: { Ref: "AWS::StackName" }
Export:
Name: TheStackWithTheThing
Creates an export with a well-known name pointing to the name under which this stack was ultimately deployed (does not necessarily need to be the name known to the CDK at deployment time).
Or do you mean, why can stackName
be scoped? Because then the answer is, yes, to detect that it came from a different Stack
object.
const stack1 = new StackWithThing(...);
const stack2 = new Stack(...);
new ThingConsumer(..., {
thingStackName: stack1.stackName // would not be the right value if nonscoped
});
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.
got it, thanks
@rix0rrr looks good, but one question: how does this relate to the logic in |
Actually, I stumbled on this limitation very early working on my prototype, so I already started working on solving this issue. So scratch my comment. |
You should never get into that situation anymore |
The clou here is: Either |
Sorry, I don't follow. You're saying the check that throws the Error in |
Sorry, I see how this is confusing. Tokens representing intrinsics (such as For nonscoped intrinsics, nothing happens, and the It used to be that You're right that we're now missing an error case in case you refer to either the region or account of a stack that's in a different region. This used to error, and it will now no longer error. I think/hope this will not be a big problem. If we thought this was going to lead to problems, we could also make a Token class that counts as scoped for the purposes of the region/account check, but still renders to a non-export/imported value. The other change is that if you refer to an other stack's fully-constructed ARN now, it won't register a stack dependency. That is actually required if we want bidirectional stack references such as you plan to do in your CI/CD work, so I don't know how to fix that. We could add in another exception that we do add a dependency for in-environment stacks but don't add a dependency for cross-environment stacks, but every new special case makes me a little sicker... |
A fully specified ARN can now be used in a different stack without
leading to a Fn::ImportValue (used to be that we incurrend an
ImportValue because of the Partition, but that is silly because
the variable is known anyway).
BREAKING CHANGE: 'Aws' class returns unscoped Tokens, introduce a
new class 'ScopedAws' which returns scoped Tokens.
Fixes #1755
Pull Request Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.