From 9effc6b750d98ff78cfd4b2489590b4c09cdb906 Mon Sep 17 00:00:00 2001 From: Bibhu Pala Date: Thu, 19 Oct 2023 23:50:54 +0530 Subject: [PATCH] Changing InstanceType regex values to add hyphen --- packages/aws-cdk-lib/aws-ec2/lib/instance-types.ts | 2 +- packages/aws-cdk-lib/aws-ec2/test/instance.test.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-ec2/lib/instance-types.ts b/packages/aws-cdk-lib/aws-ec2/lib/instance-types.ts index 97ba5060001c7..56fb1d67676ce 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/instance-types.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/instance-types.ts @@ -1390,7 +1390,7 @@ export class InstanceType { } public sameInstanceClassAs(other: InstanceType): boolean { - const instanceClass: RegExp = /^([a-z]+\d{1,2}[a-z]*)\.([a-z0-9]+)$/; + const instanceClass: RegExp = /^([a-z-]+\d{1,2}[a-z-]*)\.([a-z0-9-]+)$/; const instanceClassId = this.instanceTypeIdentifier.match(instanceClass); const otherInstanceClassId = other.instanceTypeIdentifier.match(instanceClass); if (instanceClassId == null || otherInstanceClassId == null) { diff --git a/packages/aws-cdk-lib/aws-ec2/test/instance.test.ts b/packages/aws-cdk-lib/aws-ec2/test/instance.test.ts index 3dcde47e3b5a8..f656ec0c3553d 100644 --- a/packages/aws-cdk-lib/aws-ec2/test/instance.test.ts +++ b/packages/aws-cdk-lib/aws-ec2/test/instance.test.ts @@ -679,6 +679,15 @@ test('sameInstanceClassAs compares identical InstanceTypes correctly', () => { expect(sameInstanceType.sameInstanceClassAs(comparitor)).toBeTruthy(); }); +test('sameInstanceClassAs compares identical InstanceTypes correctly', () => { + // GIVEN + const comparitor = InstanceType.of(InstanceClass.M7I_FLEX, InstanceSize.LARGE); + //WHEN + const instanceType = new InstanceType('m7i-flex.large'); + //THEN + expect(instanceType.sameInstanceClassAs(comparitor)).toBeTruthy(); +}); + test('sameInstanceClassAs compares InstanceTypes correctly regardless of size', () => { // GIVEN const comparitor = InstanceType.of(InstanceClass.T3, InstanceSize.LARGE);