From 0e86b2e24fe434743d762e2818091eeb345d2947 Mon Sep 17 00:00:00 2001 From: Danil Agafonov Date: Thu, 11 May 2023 11:34:00 -0700 Subject: [PATCH] generate name on synth if resource passed between stages --- packages/aws-cdk-lib/core/lib/resource.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/aws-cdk-lib/core/lib/resource.ts b/packages/aws-cdk-lib/core/lib/resource.ts index ee79dc233fdb8..d0a2375400878 100644 --- a/packages/aws-cdk-lib/core/lib/resource.ts +++ b/packages/aws-cdk-lib/core/lib/resource.ts @@ -6,6 +6,7 @@ import { Reference } from './reference'; import { RemovalPolicy } from './removal-policy'; import { IResolveContext } from './resolvable'; import { Stack } from './stack'; +import { Stage } from "./stage"; import { Token, Tokenization } from './token'; // v2 - leave this as a separate section so it reduces merge conflicts when compat is removed @@ -258,7 +259,8 @@ export abstract class Resource extends Construct implements IResource { if (this.stack.account !== consumingStack.account || (this.stack.region !== consumingStack.region && - !consumingStack._crossRegionReferences)) { + !consumingStack._crossRegionReferences) || + Stage.of(this) !== Stage.of(consumingStack)) { this._enableCrossEnvironment(); return this.physicalName; } else { @@ -291,7 +293,8 @@ export abstract class Resource extends Construct implements IResource { const consumingStack = Stack.of(context.scope); if (this.stack.account !== consumingStack.account || (this.stack.region !== consumingStack.region && - !consumingStack._crossRegionReferences)) { + !consumingStack._crossRegionReferences) || + Stage.of(this) !== Stage.of(consumingStack)) { this._enableCrossEnvironment(); return this.stack.formatArn(arnComponents); } else {