@@ -2,6 +2,8 @@ import { Template } from '@aws-cdk/assertions';
2
2
import * as iam from '@aws-cdk/aws-iam' ;
3
3
import * as sfn from '@aws-cdk/aws-stepfunctions' ;
4
4
import * as cdk from '@aws-cdk/core' ;
5
+ // eslint-disable-next-line import/no-extraneous-dependencies
6
+ import { ENABLE_EMR_SERVICE_POLICY_V2 } from '@aws-cdk/cx-api' ;
5
7
import { EmrCreateCluster } from '../../lib' ;
6
8
7
9
let stack : cdk . Stack ;
@@ -681,7 +683,92 @@ test('Create Cluster without Roles', () => {
681
683
] ,
682
684
} ,
683
685
} ) ;
686
+ } ) ;
687
+
688
+ test ( 'Create Cluster with AmazonElasticMapReduceRole managed policies' , ( ) => {
689
+ // WHEN
690
+ const app = new cdk . App ( { context : { [ ENABLE_EMR_SERVICE_POLICY_V2 ] : false } } ) ;
691
+ const newStack = new cdk . Stack ( app , 'NewStack' ) ;
692
+
693
+ new EmrCreateCluster ( newStack , 'Task' , {
694
+ instances : { } ,
695
+ name : 'Cluster' ,
696
+ integrationPattern : sfn . IntegrationPattern . RUN_JOB ,
697
+ } ) ;
698
+
699
+ // THEN
700
+ Template . fromStack ( newStack ) . hasResourceProperties ( 'AWS::IAM::Role' , {
701
+ AssumeRolePolicyDocument : {
702
+ Version : '2012-10-17' ,
703
+ Statement : [
704
+ {
705
+ Principal : { Service : 'elasticmapreduce.amazonaws.com' } ,
706
+ Action : 'sts:AssumeRole' ,
707
+ Effect : 'Allow' ,
708
+ } ,
709
+ ] ,
710
+ } ,
711
+ ManagedPolicyArns : [
712
+ {
713
+ 'Fn::Join' : [
714
+ '' ,
715
+ [
716
+ 'arn:' ,
717
+ {
718
+ Ref : 'AWS::Partition' ,
719
+ } ,
720
+ ':iam::aws:policy/service-role/AmazonElasticMapReduceRole' ,
721
+ ] ,
722
+ ] ,
723
+ } ,
724
+ ] ,
725
+ } ) ;
726
+ } ) ;
684
727
728
+
729
+ test ( 'Create Cluster with AmazonEMRServicePolicy_v2 managed policies' , ( ) => {
730
+ // WHEN
731
+ const app = new cdk . App ( { context : { [ ENABLE_EMR_SERVICE_POLICY_V2 ] : true } } ) ;
732
+ const newStack = new cdk . Stack ( app , 'NewStack' ) ;
733
+
734
+ new EmrCreateCluster ( newStack , 'Task' , {
735
+ instances : { } ,
736
+ name : 'Cluster' ,
737
+ integrationPattern : sfn . IntegrationPattern . RUN_JOB ,
738
+ } ) ;
739
+
740
+ // THEN
741
+ Template . fromStack ( newStack ) . hasResourceProperties ( 'AWS::IAM::Role' , {
742
+ AssumeRolePolicyDocument : {
743
+ Version : '2012-10-17' ,
744
+ Statement : [
745
+ {
746
+ Principal : { Service : 'elasticmapreduce.amazonaws.com' } ,
747
+ Action : 'sts:AssumeRole' ,
748
+ Effect : 'Allow' ,
749
+ Condition : {
750
+ StringEquals : {
751
+ 'aws:RequestTag/for-use-with-amazon-emr-managed-policies' : 'true' ,
752
+ } ,
753
+ } ,
754
+ } ,
755
+ ] ,
756
+ } ,
757
+ ManagedPolicyArns : [
758
+ {
759
+ 'Fn::Join' : [
760
+ '' ,
761
+ [
762
+ 'arn:' ,
763
+ {
764
+ Ref : 'AWS::Partition' ,
765
+ } ,
766
+ ':iam::aws:policy/service-role/AmazonEMRServicePolicy_v2' ,
767
+ ] ,
768
+ ] ,
769
+ } ,
770
+ ] ,
771
+ } ) ;
685
772
} ) ;
686
773
687
774
test ( 'Create Cluster with Instances configuration' , ( ) => {
0 commit comments