-
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: stack.partition is never scoped #1763
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,49 @@ import { CfnReference } from './cfn-tokens'; | |
* values can be obtained as properties from an scoped object. | ||
*/ | ||
export class Aws { | ||
private constructor() { | ||
} | ||
|
||
public static get accountId(): string { | ||
return new AwsAccountId(undefined).toString(); | ||
} | ||
|
||
public static get urlSuffix(): string { | ||
return new AwsURLSuffix(undefined).toString(); | ||
} | ||
|
||
public static get notificationArns(): string[] { | ||
return new AwsNotificationARNs(undefined).toList(); | ||
} | ||
|
||
public static get partition(): string { | ||
return new AwsPartition(undefined).toString(); | ||
} | ||
|
||
public static get region(): string { | ||
return new AwsRegion(undefined).toString(); | ||
} | ||
|
||
public static get stackId(): string { | ||
return new AwsStackId(undefined).toString(); | ||
} | ||
|
||
public static get stackName(): string { | ||
return new AwsStackName(undefined).toString(); | ||
} | ||
|
||
public static get noValue(): string { | ||
return new AwsNoValue().toString(); | ||
} | ||
} | ||
|
||
/** | ||
* Accessor for scoped pseudo parameters | ||
* | ||
* These pseudo parameters are anchored to a stack somewhere in the construct | ||
* tree, and their values will be exported automatically. | ||
*/ | ||
export class ScopedAws { | ||
constructor(private readonly scope?: Construct) { | ||
} | ||
|
||
|
@@ -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 commentThe 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 commentThe 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 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 commentThe reason will be displayed to describe this comment to others. Learn more. got it, thanks |
||
} | ||
|
||
public get noValue(): string { | ||
return new AwsNoValue().toString(); | ||
} | ||
} | ||
|
||
class PseudoParameter extends CfnReference { | ||
|
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 😊
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.
Was trying to figure out why the comments indicated a scope was needed, this explains why the comment is outdated
https://github.com/aws/aws-cdk/blob/v2.173.0/packages/aws-cdk-lib/core/lib/cfn-pseudo.ts#L21