@@ -83,6 +83,13 @@ export interface IProject extends IResource, iam.IGrantable, ec2.IConnectable, n
8383 /** The IAM service Role of this Project. Undefined for imported Projects. */
8484 readonly role ?: iam . IRole ;
8585
86+ /**
87+ * If true, batch builds have been enabled.
88+ *
89+ * @default false - batch builds have not been enabled.
90+ */
91+ readonly isBatchBuildEnabled : boolean ;
92+
8693 /**
8794 * Enable batch builds.
8895 *
@@ -268,6 +275,12 @@ abstract class ProjectBase extends Resource implements IProject {
268275 */
269276 protected _connections : ec2 . Connections | undefined ;
270277
278+ /**
279+ * Actual value will be determined for a Project
280+ * using a getter depending on the effect of enableBatchBuilds
281+ */
282+ public readonly isBatchBuildEnabled = false ;
283+
271284 /**
272285 * Access the Connections object.
273286 * Will fail if this Project does not have a VPC set.
@@ -1045,6 +1058,7 @@ export class Project extends ProjectBase {
10451058 private readonly _secondarySources : CfnProject . SourceProperty [ ] ;
10461059 private readonly _secondarySourceVersions : CfnProject . ProjectSourceVersionProperty [ ] ;
10471060 private readonly _secondaryArtifacts : CfnProject . ArtifactsProperty [ ] ;
1061+ private readonly _environment ?: CfnProject . EnvironmentProperty ;
10481062 private _encryptionKey ?: kms . IKey ;
10491063 private readonly _fileSystemLocations : CfnProject . ProjectFileSystemLocationProperty [ ] ;
10501064 private _batchServiceRole ?: iam . Role ;
@@ -1107,6 +1121,8 @@ export class Project extends ProjectBase {
11071121 this . addFileSystemLocation ( fileSystemLocation ) ;
11081122 }
11091123
1124+ this . _environment = this . renderEnvironment ( props , environmentVariables ) ;
1125+
11101126 const resource = new CfnProject ( this , 'Resource' , {
11111127 description : props . description ,
11121128 source : {
@@ -1115,7 +1131,7 @@ export class Project extends ProjectBase {
11151131 } ,
11161132 artifacts : artifactsConfig . artifactsProperty ,
11171133 serviceRole : this . role . roleArn ,
1118- environment : this . renderEnvironment ( props , environmentVariables ) ,
1134+ environment : this . _environment ,
11191135 fileSystemLocations : Lazy . any ( { produce : ( ) => this . renderFileSystemLocations ( ) } ) ,
11201136 // lazy, because we have a setter for it in setEncryptionKey
11211137 // The 'alias/aws/s3' default is necessary because leaving the `encryptionKey` field
@@ -1204,7 +1220,15 @@ export class Project extends ProjectBase {
12041220 this . node . addValidation ( { validate : ( ) => this . validateProject ( ) } ) ;
12051221 }
12061222
1223+ public get isBatchBuildsEnabled ( ) : boolean {
1224+ return ! ! this . _batchServiceRole ;
1225+ }
1226+
12071227 public enableBatchBuilds ( ) : BatchBuildConfig | undefined {
1228+ if ( this . _environment ?. fleet ) {
1229+ throw new Error ( 'Build batch is not supported for project using reserved capacity' ) ;
1230+ }
1231+
12081232 if ( ! this . _batchServiceRole ) {
12091233 this . _batchServiceRole = new iam . Role ( this , 'BatchServiceRole' , {
12101234 assumedBy : new iam . ServicePrincipal ( 'codebuild.amazonaws.com' ) ,
@@ -1426,6 +1450,13 @@ export class Project extends ProjectBase {
14261450 return undefined ;
14271451 }
14281452
1453+ // !! Failsafe !! This should not occur with the current methods, given:
1454+ // * The fleet can only be set with the constructor
1455+ // * The batch builds can only be enabled with the `enableBatchBuilds` method
1456+ if ( this . isBatchBuildEnabled ) {
1457+ throw new Error ( 'Build batch is not supported for project using reserved capacity' ) ;
1458+ }
1459+
14291460 // If the fleetArn is resolved, the fleet is imported and we cannot validate the environment type
14301461 if ( Token . isUnresolved ( fleet . fleetArn ) && this . buildImage . type !== fleet . environmentType ) {
14311462 throw new Error ( `The environment type of the fleet (${ fleet . environmentType } ) must match the environment type of the build image (${ this . buildImage . type } )` ) ;
0 commit comments