Skip to content

Commit

Permalink
feat(codebuild): add new environment types (aws#32729)
Browse files Browse the repository at this point in the history
### Issue # (if applicable)

Closes aws#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*
  • Loading branch information
awszhen authored Jan 4, 2025
1 parent 5305d7b commit a10c369
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/aws-cdk-lib/aws-codebuild/lib/environment-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
72 changes: 72 additions & 0 deletions packages/aws-cdk-lib/aws-codebuild/test/fleet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a10c369

Please sign in to comment.