@@ -206,6 +206,7 @@ export class Pipeline extends PipelineBase {
206
206
private readonly stages = new Array < Stage > ( ) ;
207
207
private readonly crossRegionBucketsPassed : boolean ;
208
208
private readonly _crossRegionSupport : { [ region : string ] : CrossRegionSupport } = { } ;
209
+ private readonly _crossAccountSupport : { [ account : string ] : Stack } = { } ;
209
210
210
211
constructor ( scope : Construct , id : string , props : PipelineProps = { } ) {
211
212
super ( scope , id , {
@@ -379,7 +380,11 @@ export class Pipeline extends PipelineBase {
379
380
const actionResourceStack = Stack . of ( actionResource ) ;
380
381
if ( pipelineStack . region !== actionResourceStack . region ) {
381
382
actionRegion = actionResourceStack . region ;
382
- otherStack = actionResourceStack ;
383
+ // if the resource is from a different stack in another region but the same account,
384
+ // use that stack as home for the cross-region support resources
385
+ if ( pipelineStack . account === actionResourceStack . account ) {
386
+ otherStack = actionResourceStack ;
387
+ }
383
388
}
384
389
} else {
385
390
actionRegion = action . actionProperties . region ;
@@ -570,9 +575,12 @@ export class Pipeline extends PipelineBase {
570
575
if ( action . actionProperties . resource ) {
571
576
const resourceStack = Stack . of ( action . actionProperties . resource ) ;
572
577
// check if resource is from a different account
573
- return pipelineStack . account === resourceStack . account
574
- ? undefined
575
- : resourceStack ;
578
+ if ( pipelineStack . account === resourceStack . account ) {
579
+ return undefined ;
580
+ } else {
581
+ this . _crossAccountSupport [ resourceStack . account ] = resourceStack ;
582
+ return resourceStack ;
583
+ }
576
584
}
577
585
578
586
if ( ! action . actionProperties . account ) {
@@ -593,17 +601,21 @@ export class Pipeline extends PipelineBase {
593
601
return undefined ;
594
602
}
595
603
596
- const stackId = `cross-account-support-stack-${ targetAccount } ` ;
597
- const app = this . requireApp ( ) ;
598
- let targetAccountStack = app . node . tryFindChild ( stackId ) as Stack ;
604
+ let targetAccountStack : Stack | undefined = this . _crossAccountSupport [ targetAccount ] ;
599
605
if ( ! targetAccountStack ) {
600
- targetAccountStack = new Stack ( app , stackId , {
601
- stackName : `${ pipelineStack . stackName } -support-${ targetAccount } ` ,
602
- env : {
603
- account : targetAccount ,
604
- region : action . actionProperties . region ? action . actionProperties . region : pipelineStack . region ,
605
- } ,
606
- } ) ;
606
+ const stackId = `cross-account-support-stack-${ targetAccount } ` ;
607
+ const app = this . requireApp ( ) ;
608
+ targetAccountStack = app . node . tryFindChild ( stackId ) as Stack ;
609
+ if ( ! targetAccountStack ) {
610
+ targetAccountStack = new Stack ( app , stackId , {
611
+ stackName : `${ pipelineStack . stackName } -support-${ targetAccount } ` ,
612
+ env : {
613
+ account : targetAccount ,
614
+ region : action . actionProperties . region ? action . actionProperties . region : pipelineStack . region ,
615
+ } ,
616
+ } ) ;
617
+ }
618
+ this . _crossAccountSupport [ targetAccount ] = targetAccountStack ;
607
619
}
608
620
return targetAccountStack ;
609
621
}
@@ -752,7 +764,7 @@ export class Pipeline extends PipelineBase {
752
764
if ( bucketKey ) {
753
765
encryptionKey = {
754
766
type : 'KMS' ,
755
- id : bucketKey . keyId ,
767
+ id : bucketKey . keyArn ,
756
768
} ;
757
769
}
758
770
0 commit comments