/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0
 */ import { IMachineImage , InstanceClass , InstanceSize , InstanceType , Vpc , } from '@aws-cdk/aws-ec2' ; import { Construct , Duration , RemovalPolicy , Stack , StackProps , Tags , } from '@aws-cdk/core' ; import { ApplicationProtocol } from '@aws-cdk/aws-elasticloadbalancingv2' ; import { ManagedPolicy , Role , ServicePrincipal , } from '@aws-cdk/aws-iam' ; import { PrivateHostedZone } from '@aws-cdk/aws-route53' ; import { ConfigureSpotEventPlugin , RenderQueue , Repository , SpotEventPluginFleet , Stage , ThinkboxDockerRecipes , } from 'aws-rfdk/deadline' ; import { X509CertificatePem } from 'aws-rfdk' ; /**
 * Properties for  SEPStack .
  export interface SEPStackProps extends StackProps { /**
     * The path to the directory where the staged Deadline Docker recipes are.
     */ readonly dockerRecipesStagePath : string ; /**
     * The  IMachineImage to use for Workers (needs Deadline Client installed).
      readonly workerMachineImage : IMachineImage ; /**
     * Whether the DeadlineResourceTracker stack and supporting resources already exist or not.
     */ readonly createResourceTrackerRole : boolean ; } export class SEPStack extends Stack { param scope param id param props constructor ( scope , id , props ) { super ( scope , id , props ) ; const vpc = new Vpc ( this , 'Vpc' , { maxAzs : 2 } ) ; const recipes = new ThinkboxDockerRecipes ( this , 'Image' , { stage : Stage . fromDirectory ( props . dockerRecipesStagePath ) , } ) ; const repository = new Repository ( this , 'Repository' , { vpc , version : recipes . version , repositoryInstallationTimeout : Duration . minutes ( 20 ) , removalPolicy : { database : RemovalPolicy . DESTROY , filesystem : RemovalPolicy . DESTROY , } , } ) ; const host = 'renderqueue' ; const zoneName = 'deadline-test.internal' ; const hostname = { zone : new PrivateHostedZone ( this , 'DnsZone' , { vpc , zoneName : zoneName , } ) , hostname : host , } ; const caCert = new X509CertificatePem ( this , 'RootCA' , { subject : { cn : 'SampleRootCA' , } , } ) ; const trafficEncryption = { externalTLS : { rfdkCertificate : new X509CertificatePem ( this , 'RQCert' , { subject : { cn : `${ host }.${ zoneName }` , o : 'RFDK-Sample' , ou : 'RenderQueueExternal' , } , signingCertificate : caCert , } ) , internalProtocol : ApplicationProtocol . HTTPS , } , } ; const renderQueue = new RenderQueue ( this , 'RenderQueue' , { vpc , version : recipes . version , images : recipes . renderQueueImages , repository : repository , deletionProtection : false , hostname , trafficEncryption , } ) ; if ( props . createResourceTrackerRole ) { new Role ( this , 'ResourceTrackerRole' , { assumedBy : new ServicePrincipal ( 'lambda.amazonaws.com' ) , managedPolicies : [ ManagedPolicy . fromAwsManagedPolicyName ( 'AWSThinkboxDeadlineResourceTrackerAccessPolicy' ) , ] , roleName : 'DeadlineResourceTrackerAccessRole' , } ) ; } const fleet = new SpotEventPluginFleet ( this , 'SpotEventPluginFleet' , { vpc , renderQueue , deadlineGroups : [ 'group_name' , ] , instanceTypes : [ InstanceType . of ( InstanceClass . T3 , InstanceSize . LARGE ) , ] , workerMachineImage : props . workerMachineImage , maxCapacity : 1 , } ) ; Tags . of ( fleet ) . add ( 'name' , 'SEPtest' ) ; new ConfigureSpotEventPlugin ( this , 'ConfigureSpotEventPlugin' , { vpc , renderQueue , spotFleets : [ fleet , ] , configuration : { enableResourceTracker : true , } , } ) ; } }