Skip to content

Commit

Permalink
fix: update the instance type and size reg expression to accept value…
Browse files Browse the repository at this point in the history
…s that contains dashes like m7i-flex
  • Loading branch information
moelasmar committed Nov 16, 2023
1 parent f0939f2 commit e9afa27
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-ec2/lib/instance-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,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) {
Expand Down
18 changes: 18 additions & 0 deletions packages/aws-cdk-lib/aws-ec2/test/instance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,24 @@ test('sameInstanceClassAs compares InstanceTypes correctly regardless of size',
expect(largerInstanceType.sameInstanceClassAs(comparitor)).toBeTruthy();
});

test('sameInstanceClassAs compares InstanceTypes contains dashes', () => {
// GIVEN
const comparitor = InstanceType.of(InstanceClass.M7I_FLEX, InstanceSize.LARGE);
//WHEN
const largerInstanceType = InstanceType.of(InstanceClass.M7I_FLEX, InstanceSize.XLARGE);
//THEN
expect(largerInstanceType.sameInstanceClassAs(comparitor)).toBeTruthy();
});

test('sameInstanceClassAs compares InstanceSize contains dashes', () => {
// GIVEN
const comparitor = new InstanceType('m7a.metal-48xl');
//WHEN
const largerInstanceType = new InstanceType('m7a.xlarge');
//THEN
expect(largerInstanceType.sameInstanceClassAs(comparitor)).toBeTruthy();
});

test('sameInstanceClassAs compares different InstanceTypes correctly', () => {
// GIVEN
const comparitor = InstanceType.of(InstanceClass.C4, InstanceSize.LARGE);
Expand Down

0 comments on commit e9afa27

Please sign in to comment.