Skip to content

Commit

Permalink
feat(deadline): add ability to add spot event plugin managed policies…
Browse files Browse the repository at this point in the history
… to RenderQueue (#141)
  • Loading branch information
grbartel authored Sep 30, 2020
1 parent 13fb0e8 commit b2cf9e0
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 2 deletions.
18 changes: 18 additions & 0 deletions packages/aws-rfdk/lib/deadline/lib/render-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
import {
IGrantable,
IPrincipal,
ManagedPolicy,
PolicyStatement,
ServicePrincipal,
} from '@aws-cdk/aws-iam';
Expand Down Expand Up @@ -458,6 +459,23 @@ export class RenderQueue extends RenderQueueBase implements IGrantable {
this.rqConnection.configureClientInstance(param);
}

/**
* Adds AWS Managed Policies to the Render Queue so it is able to control Deadlines Spot Event Plugin.
*
* See: https://docs.thinkboxsoftware.com/products/deadline/10.1/1_User%20Manual/manual/event-spot.html for additonal information.
*
* @param includeResourceTracker Whether or not the Resource tracker admin policy should also be addd (Default: True)
*/
public addSEPPolicies( includeResourceTracker: boolean = true): void {
const sepPolicy = ManagedPolicy.fromAwsManagedPolicyName('AWSThinkboxDeadlineSpotEventPluginAdminPolicy');
this.taskDefinition.taskRole.addManagedPolicy(sepPolicy);

if (includeResourceTracker) {
const rtPolicy = ManagedPolicy.fromAwsManagedPolicyName('AWSThinkboxDeadlineResourceTrackerAdminPolicy');
this.taskDefinition.taskRole.addManagedPolicy(rtPolicy);
}
}

/**
* Add an ordering dependency to another Construct.
*
Expand Down
75 changes: 73 additions & 2 deletions packages/aws-rfdk/lib/deadline/test/render-queue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import {
ABSENT,
arrayWith,
not,
countResourcesLike,
deepObjectLike,
expect as expectCDK,
haveResource,
haveResourceLike,
not,
objectLike,
ResourcePart,
countResourcesLike,
} from '@aws-cdk/assert';
import {
Certificate,
Expand Down Expand Up @@ -2198,4 +2198,75 @@ describe('RenderQueue', () => {
},
});
});

describe('SEP Policies', () => {
test('with resource tracker', () => {
renderQueueCommon.addSEPPolicies();
expectCDK(stack).to(countResourcesLike('AWS::IAM::Role', 1, {
ManagedPolicyArns: arrayWith(
{
'Fn::Join': [
'',
[
'arn:',
{
Ref: 'AWS::Partition',
},
':iam::aws:policy/AWSThinkboxDeadlineSpotEventPluginAdminPolicy',
],
],
},
{
'Fn::Join': [
'',
[
'arn:',
{
Ref: 'AWS::Partition',
},
':iam::aws:policy/AWSThinkboxDeadlineResourceTrackerAdminPolicy',
],
],
},
),
}));
});

test('no resource tracker', () => {
renderQueueCommon.addSEPPolicies(false);
expectCDK(stack).to(haveResourceLike('AWS::IAM::Role', {
ManagedPolicyArns: arrayWith(
{
'Fn::Join': [
'',
[
'arn:',
{
Ref: 'AWS::Partition',
},
':iam::aws:policy/AWSThinkboxDeadlineSpotEventPluginAdminPolicy',
],
],
},
),
}));
expectCDK(stack).notTo(haveResourceLike('AWS::IAM::Role', {
ManagedPolicyArns: arrayWith(
{
'Fn::Join': [
'',
[
'arn:',
{
Ref: 'AWS::Partition',
},
':iam::aws:policy/AWSThinkboxDeadlineResourceTrackerAdminPolicy',
],
],
},
),
}));
});

});
});

0 comments on commit b2cf9e0

Please sign in to comment.