Skip to content

Commit a10c369

Browse files
authored
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*
1 parent 5305d7b commit a10c369

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

packages/aws-cdk-lib/aws-codebuild/lib/environment-type.ts

+6
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ export enum EnvironmentType {
1616
WINDOWS_SERVER_2022_CONTAINER = 'WINDOWS_SERVER_2022_CONTAINER',
1717
/** MacOS ARM container */
1818
MAC_ARM = 'MAC_ARM',
19+
/** Linux EC2 */
20+
LINUX_EC2 = 'LINUX_EC2',
21+
/** ARM EC2 */
22+
ARM_EC2 = 'ARM_EC2',
23+
/** Windows EC2 */
24+
WINDOWS_EC2 = 'WINDOWS_EC2',
1925
}

packages/aws-cdk-lib/aws-codebuild/test/fleet.test.ts

+72
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,78 @@ test('can construct a default fleet', () => {
2626
expect(fleet.environmentType).toEqual(codebuild.EnvironmentType.LINUX_CONTAINER);
2727
});
2828

29+
test('can construct a LINUX_EC2 fleet', () => {
30+
// GIVEN
31+
const stack = new cdk.Stack();
32+
33+
// WHEN
34+
const fleet = new codebuild.Fleet(stack, 'Fleet', {
35+
computeType: codebuild.FleetComputeType.SMALL,
36+
environmentType: codebuild.EnvironmentType.LINUX_EC2,
37+
baseCapacity: 1,
38+
});
39+
40+
// THEN
41+
Template.fromStack(stack).hasResourceProperties('AWS::CodeBuild::Fleet', {
42+
Name: Match.absent(),
43+
BaseCapacity: 1,
44+
ComputeType: 'BUILD_GENERAL1_SMALL',
45+
EnvironmentType: 'LINUX_EC2',
46+
});
47+
expect(cdk.Token.isUnresolved(fleet.fleetName)).toBeTruthy();
48+
expect(cdk.Token.isUnresolved(fleet.fleetArn)).toBeTruthy();
49+
expect(fleet.computeType).toEqual(codebuild.FleetComputeType.SMALL);
50+
expect(fleet.environmentType).toEqual(codebuild.EnvironmentType.LINUX_EC2);
51+
});
52+
53+
test('can construct an ARM_EC2 fleet', () => {
54+
// GIVEN
55+
const stack = new cdk.Stack();
56+
57+
// WHEN
58+
const fleet = new codebuild.Fleet(stack, 'Fleet', {
59+
computeType: codebuild.FleetComputeType.SMALL,
60+
environmentType: codebuild.EnvironmentType.ARM_EC2,
61+
baseCapacity: 1,
62+
});
63+
64+
// THEN
65+
Template.fromStack(stack).hasResourceProperties('AWS::CodeBuild::Fleet', {
66+
Name: Match.absent(),
67+
BaseCapacity: 1,
68+
ComputeType: 'BUILD_GENERAL1_SMALL',
69+
EnvironmentType: 'ARM_EC2',
70+
});
71+
expect(cdk.Token.isUnresolved(fleet.fleetName)).toBeTruthy();
72+
expect(cdk.Token.isUnresolved(fleet.fleetArn)).toBeTruthy();
73+
expect(fleet.computeType).toEqual(codebuild.FleetComputeType.SMALL);
74+
expect(fleet.environmentType).toEqual(codebuild.EnvironmentType.ARM_EC2);
75+
});
76+
77+
test('can construct a WINDOWS_EC2 fleet', () => {
78+
// GIVEN
79+
const stack = new cdk.Stack();
80+
81+
// WHEN
82+
const fleet = new codebuild.Fleet(stack, 'Fleet', {
83+
computeType: codebuild.FleetComputeType.MEDIUM,
84+
environmentType: codebuild.EnvironmentType.WINDOWS_EC2,
85+
baseCapacity: 1,
86+
});
87+
88+
// THEN
89+
Template.fromStack(stack).hasResourceProperties('AWS::CodeBuild::Fleet', {
90+
Name: Match.absent(),
91+
BaseCapacity: 1,
92+
ComputeType: 'BUILD_GENERAL1_MEDIUM',
93+
EnvironmentType: 'WINDOWS_EC2',
94+
});
95+
expect(cdk.Token.isUnresolved(fleet.fleetName)).toBeTruthy();
96+
expect(cdk.Token.isUnresolved(fleet.fleetArn)).toBeTruthy();
97+
expect(fleet.computeType).toEqual(codebuild.FleetComputeType.MEDIUM);
98+
expect(fleet.environmentType).toEqual(codebuild.EnvironmentType.WINDOWS_EC2);
99+
});
100+
29101
test('can construct a fleet with a specified name', () => {
30102
// GIVEN
31103
const stack = new cdk.Stack();

0 commit comments

Comments
 (0)