|
1 | 1 | import { Template } from 'aws-cdk-lib/assertions';
|
2 | 2 | import * as ecs from 'aws-cdk-lib/aws-ecs';
|
3 | 3 | import { DefaultTokenResolver, Size, StringConcat, Stack, Tokenization } from 'aws-cdk-lib';
|
4 |
| -import { Compatibility, EcsEc2ContainerDefinition, EcsFargateContainerDefinition, EcsJobDefinition } from '../lib'; |
| 4 | +import * as iam from 'aws-cdk-lib/aws-iam'; |
| 5 | +import { Compatibility, EcsEc2ContainerDefinition, EcsFargateContainerDefinition, EcsJobDefinition, JobQueue, ManagedEc2EcsComputeEnvironment } from '../lib'; |
| 6 | +import { Vpc } from 'aws-cdk-lib/aws-ec2'; |
5 | 7 |
|
6 | 8 | test('EcsJobDefinition respects propagateTags', () => {
|
7 | 9 | // GIVEN
|
@@ -127,3 +129,44 @@ test('JobDefinitionName is parsed from arn in imported job', () => {
|
127 | 129 | // THEN
|
128 | 130 | expect(importedJob.jobDefinitionName).toEqual('job-def-name');
|
129 | 131 | });
|
| 132 | + |
| 133 | +test('grantSubmitJob() grants the job role the correct actions', () => { |
| 134 | + // GIVEN |
| 135 | + const stack = new Stack(); |
| 136 | + const ecsJob = new EcsJobDefinition(stack, 'ECSJob', { |
| 137 | + container: new EcsFargateContainerDefinition(stack, 'EcsContainer', { |
| 138 | + cpu: 256, |
| 139 | + memory: Size.mebibytes(2048), |
| 140 | + image: ecs.ContainerImage.fromRegistry('foorepo/fooimage'), |
| 141 | + }), |
| 142 | + }); |
| 143 | + const queue = new JobQueue(stack, 'queue'); |
| 144 | + |
| 145 | + queue.addComputeEnvironment( |
| 146 | + new ManagedEc2EcsComputeEnvironment(stack, 'env', { |
| 147 | + vpc: new Vpc(stack, 'VPC'), |
| 148 | + }), |
| 149 | + 1, |
| 150 | + ); |
| 151 | + |
| 152 | + const user = new iam.User(stack, 'MyUser'); |
| 153 | + |
| 154 | + // WHEN |
| 155 | + ecsJob.grantSubmitJob(user, queue); |
| 156 | + |
| 157 | + // THEN |
| 158 | + Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { |
| 159 | + PolicyDocument: { |
| 160 | + Statement: [{ |
| 161 | + Action: 'batch:SubmitJob', |
| 162 | + Effect: 'Allow', |
| 163 | + Resource: [ |
| 164 | + { Ref: 'ECSJobFFFEA569' }, |
| 165 | + { 'Fn::GetAtt': ['queue276F7297', 'JobQueueArn'] }, |
| 166 | + ], |
| 167 | + }], |
| 168 | + Version: '2012-10-17', |
| 169 | + }, |
| 170 | + PolicyName: 'MyUserDefaultPolicy7B897426', |
| 171 | + }); |
| 172 | +}); |
0 commit comments