From a10c369bfc65c37217e289c06673889b1ff99476 Mon Sep 17 00:00:00 2001 From: awszhen <32624806+awszhen@users.noreply.github.com> Date: Fri, 3 Jan 2025 17:33:51 -0800 Subject: [PATCH] feat(codebuild): add new environment types (#32729) ### Issue # (if applicable) Closes #32728. ### Reason for this change Recently, CodeBuild released a new set of environment types which can be found [here](https://docs.aws.amazon.com/codebuild/latest/APIReference/API_CreateFleet.html#CodeBuild-CreateFleet-request-environmentType): `LINUX_EC2`, `ARM_EC2` and `WINDOWS_EC2`. The CDK needs to be extended to support these new environment types. ### Description of changes Added `LINUX_EC2`, `ARM_EC2` and `WINDOWS_EC2` values to [EnvironmentType](https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-codebuild/lib/environment-type.ts). ### Description of how you validated changes Tests has been added. I ensured that the CDK was able to build, and that the output CloudFormation stack had the correct resources. ### Checklist - [X] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../aws-codebuild/lib/environment-type.ts | 6 ++ .../aws-codebuild/test/fleet.test.ts | 72 +++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/packages/aws-cdk-lib/aws-codebuild/lib/environment-type.ts b/packages/aws-cdk-lib/aws-codebuild/lib/environment-type.ts index bcc23e8c3f4e3..dd6df4e6bc417 100644 --- a/packages/aws-cdk-lib/aws-codebuild/lib/environment-type.ts +++ b/packages/aws-cdk-lib/aws-codebuild/lib/environment-type.ts @@ -16,4 +16,10 @@ export enum EnvironmentType { WINDOWS_SERVER_2022_CONTAINER = 'WINDOWS_SERVER_2022_CONTAINER', /** MacOS ARM container */ MAC_ARM = 'MAC_ARM', + /** Linux EC2 */ + LINUX_EC2 = 'LINUX_EC2', + /** ARM EC2 */ + ARM_EC2 = 'ARM_EC2', + /** Windows EC2 */ + WINDOWS_EC2 = 'WINDOWS_EC2', } diff --git a/packages/aws-cdk-lib/aws-codebuild/test/fleet.test.ts b/packages/aws-cdk-lib/aws-codebuild/test/fleet.test.ts index d538541e44a7f..8a9466e5b3807 100644 --- a/packages/aws-cdk-lib/aws-codebuild/test/fleet.test.ts +++ b/packages/aws-cdk-lib/aws-codebuild/test/fleet.test.ts @@ -26,6 +26,78 @@ test('can construct a default fleet', () => { expect(fleet.environmentType).toEqual(codebuild.EnvironmentType.LINUX_CONTAINER); }); +test('can construct a LINUX_EC2 fleet', () => { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + const fleet = new codebuild.Fleet(stack, 'Fleet', { + computeType: codebuild.FleetComputeType.SMALL, + environmentType: codebuild.EnvironmentType.LINUX_EC2, + baseCapacity: 1, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::CodeBuild::Fleet', { + Name: Match.absent(), + BaseCapacity: 1, + ComputeType: 'BUILD_GENERAL1_SMALL', + EnvironmentType: 'LINUX_EC2', + }); + expect(cdk.Token.isUnresolved(fleet.fleetName)).toBeTruthy(); + expect(cdk.Token.isUnresolved(fleet.fleetArn)).toBeTruthy(); + expect(fleet.computeType).toEqual(codebuild.FleetComputeType.SMALL); + expect(fleet.environmentType).toEqual(codebuild.EnvironmentType.LINUX_EC2); +}); + +test('can construct an ARM_EC2 fleet', () => { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + const fleet = new codebuild.Fleet(stack, 'Fleet', { + computeType: codebuild.FleetComputeType.SMALL, + environmentType: codebuild.EnvironmentType.ARM_EC2, + baseCapacity: 1, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::CodeBuild::Fleet', { + Name: Match.absent(), + BaseCapacity: 1, + ComputeType: 'BUILD_GENERAL1_SMALL', + EnvironmentType: 'ARM_EC2', + }); + expect(cdk.Token.isUnresolved(fleet.fleetName)).toBeTruthy(); + expect(cdk.Token.isUnresolved(fleet.fleetArn)).toBeTruthy(); + expect(fleet.computeType).toEqual(codebuild.FleetComputeType.SMALL); + expect(fleet.environmentType).toEqual(codebuild.EnvironmentType.ARM_EC2); +}); + +test('can construct a WINDOWS_EC2 fleet', () => { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + const fleet = new codebuild.Fleet(stack, 'Fleet', { + computeType: codebuild.FleetComputeType.MEDIUM, + environmentType: codebuild.EnvironmentType.WINDOWS_EC2, + baseCapacity: 1, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::CodeBuild::Fleet', { + Name: Match.absent(), + BaseCapacity: 1, + ComputeType: 'BUILD_GENERAL1_MEDIUM', + EnvironmentType: 'WINDOWS_EC2', + }); + expect(cdk.Token.isUnresolved(fleet.fleetName)).toBeTruthy(); + expect(cdk.Token.isUnresolved(fleet.fleetArn)).toBeTruthy(); + expect(fleet.computeType).toEqual(codebuild.FleetComputeType.MEDIUM); + expect(fleet.environmentType).toEqual(codebuild.EnvironmentType.WINDOWS_EC2); +}); + test('can construct a fleet with a specified name', () => { // GIVEN const stack = new cdk.Stack();