1
1
import { Template } from '@aws-cdk/assertions' ;
2
2
import { testDeprecated } from '@aws-cdk/cdk-build-tools' ;
3
- import { Duration , Stack , App } from '@aws-cdk/core' ;
3
+ import { Duration , Stack , App , CfnResource } from '@aws-cdk/core' ;
4
4
import { AnyPrincipal , ArnPrincipal , CompositePrincipal , FederatedPrincipal , ManagedPolicy , PolicyStatement , Role , ServicePrincipal , User , Policy , PolicyDocument } from '../lib' ;
5
5
6
6
describe ( 'IAM role' , ( ) => {
@@ -569,4 +569,34 @@ test('managed policy ARNs are deduplicated', () => {
569
569
} ,
570
570
] ,
571
571
} ) ;
572
- } ) ;
572
+ } ) ;
573
+
574
+ test ( 'cross-env role ARNs include path' , ( ) => {
575
+ const app = new App ( ) ;
576
+ const roleStack = new Stack ( app , 'role-stack' , { env : { account : '123456789012' , region : 'us-east-1' } } ) ;
577
+ const referencerStack = new Stack ( app , 'referencer-stack' , { env : { region : 'us-east-2' } } ) ;
578
+ const role = new Role ( roleStack , 'Role' , {
579
+ assumedBy : new ServicePrincipal ( 'sns.amazonaws.com' ) ,
580
+ path : '/sample/path/' ,
581
+ roleName : 'sample-name' ,
582
+ } ) ;
583
+ new CfnResource ( referencerStack , 'Referencer' , {
584
+ type : 'Custom::RoleReferencer' ,
585
+ properties : { RoleArn : role . roleArn } ,
586
+ } ) ;
587
+
588
+ Template . fromStack ( referencerStack ) . hasResourceProperties ( 'Custom::RoleReferencer' , {
589
+ RoleArn : {
590
+ 'Fn::Join' : [
591
+ '' ,
592
+ [
593
+ 'arn:' ,
594
+ {
595
+ Ref : 'AWS::Partition' ,
596
+ } ,
597
+ ':iam::123456789012:role/sample/path/sample-name' ,
598
+ ] ,
599
+ ] ,
600
+ } ,
601
+ } ) ;
602
+ } ) ;
0 commit comments