aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 11.3 kB
JavaScript
;var __esDecorate=exports&&exports.__esDecorate||function(ctor,descriptorIn,decorators,contextIn,initializers,extraInitializers){function accept(f){if(f!==void 0&&typeof f!="function")throw new TypeError("Function expected");return f}for(var kind=contextIn.kind,key=kind==="getter"?"get":kind==="setter"?"set":"value",target=!descriptorIn&&ctor?contextIn.static?ctor:ctor.prototype:null,descriptor=descriptorIn||(target?Object.getOwnPropertyDescriptor(target,contextIn.name):{}),_,done=!1,i=decorators.length-1;i>=0;i--){var context={};for(var p in contextIn)context[p]=p==="access"?{}:contextIn[p];for(var p in contextIn.access)context.access[p]=contextIn.access[p];context.addInitializer=function(f){if(done)throw new TypeError("Cannot add initializers after decoration has completed");extraInitializers.push(accept(f||null))};var result=(0,decorators[i])(kind==="accessor"?{get:descriptor.get,set:descriptor.set}:descriptor[key],context);if(kind==="accessor"){if(result===void 0)continue;if(result===null||typeof result!="object")throw new TypeError("Object expected");(_=accept(result.get))&&(descriptor.get=_),(_=accept(result.set))&&(descriptor.set=_),(_=accept(result.init))&&initializers.unshift(_)}else(_=accept(result))&&(kind==="field"?initializers.unshift(_):descriptor[key]=_)}target&&Object.defineProperty(target,contextIn.name,descriptor),done=!0},__runInitializers=exports&&exports.__runInitializers||function(thisArg,initializers,value){for(var useValue=arguments.length>2,i=0;i<initializers.length;i++)value=useValue?initializers[i].call(thisArg,value):initializers[i].call(thisArg);return useValue?value:void 0};Object.defineProperty(exports,"__esModule",{value:!0}),exports.FleetOverflowBehavior=exports.FleetComputeType=exports.Fleet=exports.MachineType=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var codebuild_generated_1=()=>{var tmp=require("./codebuild.generated");return codebuild_generated_1=()=>tmp,tmp},compute_type_1=()=>{var tmp=require("./compute-type");return compute_type_1=()=>tmp,tmp},ec2=()=>{var tmp=require("../../aws-ec2");return ec2=()=>tmp,tmp},iam=()=>{var tmp=require("../../aws-iam");return iam=()=>tmp,tmp},core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp},metadata_resource_1=()=>{var tmp=require("../../core/lib/metadata-resource");return metadata_resource_1=()=>tmp,tmp},prop_injectable_1=()=>{var tmp=require("../../core/lib/prop-injectable");return prop_injectable_1=()=>tmp,tmp},MachineType;(function(MachineType2){MachineType2.GENERAL="GENERAL",MachineType2.NVME="NVME"})(MachineType||(exports.MachineType=MachineType={}));let Fleet=(()=>{let _classDecorators=[prop_injectable_1().propertyInjectable],_classDescriptor,_classExtraInitializers=[],_classThis,_classSuper=core_1().Resource;var Fleet2=class extends _classSuper{static{_classThis=this}static{const _metadata=typeof Symbol=="function"&&Symbol.metadata?Object.create(_classSuper[Symbol.metadata]??null):void 0;__esDecorate(null,_classDescriptor={value:_classThis},_classDecorators,{kind:"class",name:_classThis.name,metadata:_metadata},null,_classExtraInitializers),Fleet2=_classThis=_classDescriptor.value,_metadata&&Object.defineProperty(_classThis,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:_metadata})}static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_codebuild.Fleet",version:"2.233.0"};static PROPERTY_INJECTION_ID="aws-cdk-lib.aws-codebuild.Fleet";static fromFleetArn(scope,id,fleetArn){class Import extends core_1().Resource{grantPrincipal=new(iam()).UnknownPrincipal({resource:this});fleetName=core_1().Arn.split(fleetArn,core_1().ArnFormat.SLASH_RESOURCE_NAME).resourceName.split(":")[0];fleetArn=fleetArn;get computeType(){throw new(core_1()).UnscopedValidationError("Cannot retrieve computeType property from an imported Fleet")}get environmentType(){throw new(core_1()).UnscopedValidationError("Cannot retrieve environmentType property from an imported Fleet")}get computeConfiguration(){throw new(core_1()).UnscopedValidationError("Cannot retrieve computeConfiguration property from an imported Fleet")}get connections(){throw new(core_1()).UnscopedValidationError("Cannot retrieve connections property from an imported Fleet")}}return new Import(scope,id)}fleetArn;fleetName;computeType;environmentType;_connections;get connections(){if(!this._connections)throw new(core_1()).ValidationError('Only VPC-associated Fleets have security groups to manage. Supply the "vpc" parameter when creating the Fleet',this);return this._connections}role;get grantPrincipal(){return this.role||(this.role=new(iam()).Role(this,"Role",{roleName:core_1().PhysicalName.GENERATE_IF_NEEDED,assumedBy:new(iam()).ServicePrincipal("codebuild.amazonaws.com")})),this.role}constructor(scope,id,props){super(scope,id,{...props,physicalName:props.fleetName});try{jsiiDeprecationWarnings().aws_cdk_lib_aws_codebuild_FleetProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,Fleet2),error}if((0,metadata_resource_1().addConstructMetadata)(this,props),this.role=props.role,props.fleetName&&!core_1().Token.isUnresolved(props.fleetName)){if(props.fleetName.length<2)throw new(core_1()).ValidationError(`Fleet name can not be shorter than 2 characters but has ${props.fleetName.length} characters.`,this);if(props.fleetName.length>128)throw new(core_1()).ValidationError(`Fleet name can not be longer than 128 characters but has ${props.fleetName.length} characters.`,this)}if((props.baseCapacity??1)<1)throw new(core_1()).ValidationError("baseCapacity must be greater than or equal to 1",this);let computeConfiguration;if(props.computeType===FleetComputeType.ATTRIBUTE_BASED){if(!props.computeConfiguration||!(props.computeConfiguration.disk||props.computeConfiguration.machineType||props.computeConfiguration.memory||props.computeConfiguration.vCpu!==void 0))throw new(core_1()).ValidationError("At least one compute configuration criteria must be specified if computeType is ATTRIBUTE_BASED",this);if(props.computeConfiguration?.instanceType)throw new(core_1()).ValidationError("instanceType can only be specified in computeConfiguration if computeType is CUSTOM_INSTANCE_TYPE",this);const computeConfig=props.computeConfiguration,diskGiB=computeConfig?.disk?.toGibibytes()??0,memoryGiB=computeConfig?.memory?.toGibibytes()??0,vCpu=computeConfig?.vCpu??0;this.validatePositiveInteger(diskGiB,"disk size"),this.validatePositiveInteger(memoryGiB,"memory size"),this.validatePositiveInteger(vCpu,"vCPU count"),computeConfiguration={disk:diskGiB,machineType:computeConfig.machineType,memory:memoryGiB,vCpu}}else if(props.computeType===FleetComputeType.CUSTOM_INSTANCE_TYPE){if(props.computeConfiguration?.instanceType){if(props.computeConfiguration.machineType||props.computeConfiguration.memory||props.computeConfiguration.vCpu)throw new(core_1()).ValidationError("computeConfiguration attributes can only be used if computeType is ATTRIBUTE_BASED",this)}else throw new(core_1()).ValidationError("instanceType must be specified in computeConfiguration if computeType is CUSTOM_INSTANCE_TYPE",this);const diskGiB=props.computeConfiguration.disk?.toGibibytes();this.validatePositiveInteger(diskGiB,"disk size"),computeConfiguration={disk:diskGiB,instanceType:props.computeConfiguration.instanceType.toString()}}else if(props.computeConfiguration)throw new(core_1()).ValidationError(`computeConfiguration can only be specified if computeType is ATTRIBUTE_BASED or CUSTOM_INSTANCE_TYPE, got: ${props.computeType}`,this);const vpcConfiguration=this.configureVpc(props),resource=new(codebuild_generated_1()).CfnFleet(this,"Resource",{name:props.fleetName,baseCapacity:props.baseCapacity,computeType:props.computeType,environmentType:props.environmentType,overflowBehavior:props.overflowBehavior,computeConfiguration,fleetVpcConfig:vpcConfiguration?.fleetVpcConfig,fleetServiceRole:this.role?.roleArn});vpcConfiguration&&resource.node.addDependency(...vpcConfiguration.policyDependables),props.vpc&&resource.node.addDependency(...props.vpc.node.findAll()),this.fleetArn=this.getResourceArnAttribute(resource.attrArn,{service:"codebuild",resource:"fleet",resourceName:this.physicalName,arnFormat:core_1().ArnFormat.SLASH_RESOURCE_NAME}),this.fleetName=this.getResourceNameAttribute(resource.ref),this.computeType=props.computeType,this.environmentType=props.environmentType}validatePositiveInteger(value,fieldName){if(value!==void 0&&!core_1().Token.isUnresolved(value)&&(value<0||!Number.isInteger(value)))throw new(core_1()).ValidationError(`${fieldName} must be a positive integer, got: ${value}`,this)}configureVpc(props){if(props.securityGroups&&!props.vpc)throw new(core_1()).ValidationError("Cannot configure securityGroups without configuring a VPC",this);if(props.subnetSelection&&!props.vpc)throw new(core_1()).ValidationError("Cannot configure subnetSelection without configuring a VPC",this);if(!props.vpc)return;let securityGroups;props.securityGroups&&props.securityGroups.length>0?securityGroups=props.securityGroups:securityGroups=[new(ec2()).SecurityGroup(this,"SecurityGroup",{vpc:props.vpc})],this._connections=new(ec2()).Connections({securityGroups});const{subnetIds}=props.vpc.selectSubnets(props.subnetSelection),networkInterfaceArn=core_1().Arn.format({service:"ec2",resource:"network-interface",resourceName:"*"},this.stack),subnetArns=subnetIds.map(subnetId=>core_1().Arn.format({service:"ec2",resource:"subnet",resourceName:subnetId},this.stack)),policyDependables=[];let addResult=this.grantPrincipal.addToPrincipalPolicy(new(iam()).PolicyStatement({actions:["ec2:CreateNetworkInterfacePermission"],resources:[networkInterfaceArn],conditions:{ArnEquals:{"ec2:Subnet":subnetArns}}}));return addResult.policyDependable&&policyDependables.push(addResult.policyDependable),addResult=this.grantPrincipal.addToPrincipalPolicy(new(iam()).PolicyStatement({actions:["ec2:DescribeDhcpOptions","ec2:DescribeNetworkInterfaces","ec2:DescribeSecurityGroups","ec2:DescribeSubnets","ec2:DescribeVpcs","ec2:CreateNetworkInterface","ec2:DeleteNetworkInterface","ec2:ModifyNetworkInterfaceAttribute"],resources:["*"]})),addResult.policyDependable&&policyDependables.push(addResult.policyDependable),{fleetVpcConfig:{vpcId:props.vpc.vpcId,subnets:subnetIds,securityGroupIds:securityGroups.map(s=>s.securityGroupId)},policyDependables}}static{__runInitializers(_classThis,_classExtraInitializers)}};return Fleet2=_classThis})();exports.Fleet=Fleet;var FleetComputeType;(function(FleetComputeType2){FleetComputeType2.SMALL="BUILD_GENERAL1_SMALL",FleetComputeType2.MEDIUM="BUILD_GENERAL1_MEDIUM",FleetComputeType2.LARGE="BUILD_GENERAL1_LARGE",FleetComputeType2.X_LARGE="BUILD_GENERAL1_XLARGE",FleetComputeType2.X2_LARGE="BUILD_GENERAL1_2XLARGE",FleetComputeType2.ATTRIBUTE_BASED="ATTRIBUTE_BASED_COMPUTE",FleetComputeType2.CUSTOM_INSTANCE_TYPE="CUSTOM_INSTANCE_TYPE"})(FleetComputeType||(exports.FleetComputeType=FleetComputeType={}));var FleetOverflowBehavior;(function(FleetOverflowBehavior2){FleetOverflowBehavior2.QUEUE="QUEUE",FleetOverflowBehavior2.ON_DEMAND="ON_DEMAND"})(FleetOverflowBehavior||(exports.FleetOverflowBehavior=FleetOverflowBehavior={}));