From 640817b51b06f6c1cb60a5002c83e75fd1a334b9 Mon Sep 17 00:00:00 2001 From: sakurai-ryo <58683719+sakurai-ryo@users.noreply.github.com> Date: Wed, 29 Nov 2023 06:51:16 +0900 Subject: [PATCH] chore(codebuild): added validation when using Windows Image (#27946) When using `WINDOWS_SERVER_2019_CONTAINER`, only MEDIUM and LARGE computeType is supported. https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-compute-types.html However, currently only ComputeType `SMALL` is validated. This PR modified to generate an error when ComputeType is specified as X2_LARGE in WindowsBuildImage. ```ts new codebuild.Project(this, 'CodeBuildCdk', { source: codebuild.Source.codeCommit({ repository: codecommit.Repository.fromRepositoryName(this, "Repo", "sample") }), environment: { computeType: codebuild.ComputeType.X2_LARGE, // generate error in synth stage buildImage: codebuild.WindowsBuildImage.WINDOWS_BASE_2_0 } }); ``` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../aws-cdk-lib/aws-codebuild/lib/project.ts | 8 +++++--- .../aws-codebuild/test/codebuild.test.ts | 20 ++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/aws-cdk-lib/aws-codebuild/lib/project.ts b/packages/aws-cdk-lib/aws-codebuild/lib/project.ts index 403fdbe7e157b..fbf0d060d3f23 100644 --- a/packages/aws-cdk-lib/aws-codebuild/lib/project.ts +++ b/packages/aws-cdk-lib/aws-codebuild/lib/project.ts @@ -1955,7 +1955,7 @@ export class WindowsBuildImage implements IBuildImage { /** * Corresponds to the standard CodeBuild image `aws/codebuild/windows-base:1.0`. * - * @deprecated `WindowsBuildImage.WINDOWS_BASE_2_0` should be used instead. + * @deprecated `WindowsBuildImage.WIN_SERVER_CORE_2019_BASE_2_0` should be used instead. */ public static readonly WIN_SERVER_CORE_2016_BASE: IBuildImage = new WindowsBuildImage({ imageId: 'aws/codebuild/windows-base:1.0', @@ -1965,6 +1965,8 @@ export class WindowsBuildImage implements IBuildImage { /** * The standard CodeBuild image `aws/codebuild/windows-base:2.0`, which is * based off Windows Server Core 2016. + * + * @deprecated `WindowsBuildImage.WIN_SERVER_CORE_2019_BASE_2_0` should be used instead. */ public static readonly WINDOWS_BASE_2_0: IBuildImage = new WindowsBuildImage({ imageId: 'aws/codebuild/windows-base:2.0', @@ -2066,8 +2068,8 @@ export class WindowsBuildImage implements IBuildImage { public validate(buildEnvironment: BuildEnvironment): string[] { const ret: string[] = []; - if (buildEnvironment.computeType === ComputeType.SMALL) { - ret.push('Windows images do not support the Small ComputeType'); + if (buildEnvironment.computeType === ComputeType.SMALL || buildEnvironment.computeType === ComputeType.X2_LARGE) { + ret.push(`Windows images do not support the '${buildEnvironment.computeType}' compute type`); } return ret; } diff --git a/packages/aws-cdk-lib/aws-codebuild/test/codebuild.test.ts b/packages/aws-cdk-lib/aws-codebuild/test/codebuild.test.ts index 3827705d56195..0e7c18857c8ad 100644 --- a/packages/aws-cdk-lib/aws-codebuild/test/codebuild.test.ts +++ b/packages/aws-cdk-lib/aws-codebuild/test/codebuild.test.ts @@ -1614,7 +1614,25 @@ test('using ComputeType.Small with a Windows image fails validation', () => { }), environment: invalidEnvironment, }); - }).toThrow(/Windows images do not support the Small ComputeType/); + }).toThrow(/Windows images do not support the 'BUILD_GENERAL1_SMALL' compute type/); +}); + +test('using ComputeType.X2Large with a Windows image fails validation', () => { + const stack = new cdk.Stack(); + const invalidEnvironment: codebuild.BuildEnvironment = { + buildImage: codebuild.WindowsBuildImage.WIN_SERVER_CORE_2019_BASE, + computeType: codebuild.ComputeType.X2_LARGE, + }; + + expect(() => { + new codebuild.Project(stack, 'MyProject', { + source: codebuild.Source.s3({ + bucket: new s3.Bucket(stack, 'MyBucket'), + path: 'path', + }), + environment: invalidEnvironment, + }); + }).toThrow(/Windows images do not support the 'BUILD_GENERAL1_2XLARGE' compute type/); }); test('fromCodebuildImage', () => {