Skip to content

Commit 3f49f02

Browse files
authored
fix(ec2): invalid volume type check for iops (#19073)
IO2 and GP3 volumes can also specify `iops` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 427cdfd commit 3f49f02

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

packages/@aws-cdk/aws-ec2/lib/private/ebs-util.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ function synthesizeBlockDeviceMappings<RT, NDT>(construct: Construct, blockDevic
3131
const { iops, volumeType, kmsKey, ...rest } = ebs;
3232

3333
if (!iops) {
34-
if (volumeType === EbsDeviceVolumeType.IO1) {
35-
throw new Error('iops property is required with volumeType: EbsDeviceVolumeType.IO1');
34+
if (volumeType === EbsDeviceVolumeType.IO1 || volumeType === EbsDeviceVolumeType.IO2) {
35+
throw new Error('iops property is required with volumeType: EbsDeviceVolumeType.IO1 and EbsDeviceVolumeType.IO2');
3636
}
37-
} else if (volumeType !== EbsDeviceVolumeType.IO1) {
38-
Annotations.of(construct).addWarning('iops will be ignored without volumeType: EbsDeviceVolumeType.IO1');
37+
} else if (volumeType !== EbsDeviceVolumeType.IO1 && volumeType !== EbsDeviceVolumeType.IO2 && volumeType !== EbsDeviceVolumeType.GP3) {
38+
Annotations.of(construct).addWarning('iops will be ignored without volumeType: IO1, IO2, or GP3');
3939
}
4040

4141
/**

packages/@aws-cdk/aws-ec2/test/instance.test.ts

+40-8
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ describe('instance', () => {
199199
volumeType: EbsDeviceVolumeType.IO1,
200200
iops: 5000,
201201
}),
202+
}, {
203+
deviceName: 'ebs-gp3',
204+
mappingEnabled: true,
205+
volume: BlockDeviceVolume.ebs(15, {
206+
deleteOnTermination: true,
207+
encrypted: true,
208+
volumeType: EbsDeviceVolumeType.GP3,
209+
iops: 5000,
210+
}),
202211
}, {
203212
deviceName: 'ebs-cmk',
204213
mappingEnabled: true,
@@ -236,6 +245,16 @@ describe('instance', () => {
236245
VolumeType: 'io1',
237246
},
238247
},
248+
{
249+
DeviceName: 'ebs-gp3',
250+
Ebs: {
251+
DeleteOnTermination: true,
252+
Encrypted: true,
253+
Iops: 5000,
254+
VolumeSize: 15,
255+
VolumeType: 'gp3',
256+
},
257+
},
239258
{
240259
DeviceName: 'ebs-cmk',
241260
Ebs: {
@@ -306,8 +325,25 @@ describe('instance', () => {
306325
}],
307326
});
308327
}).toThrow(/ops property is required with volumeType: EbsDeviceVolumeType.IO1/);
328+
});
309329

310-
330+
test('throws if volumeType === IO2 without iops', () => {
331+
// THEN
332+
expect(() => {
333+
new Instance(stack, 'Instance', {
334+
vpc,
335+
machineImage: new AmazonLinuxImage(),
336+
instanceType: InstanceType.of(InstanceClass.T3, InstanceSize.LARGE),
337+
blockDevices: [{
338+
deviceName: 'ebs',
339+
volume: BlockDeviceVolume.ebs(15, {
340+
deleteOnTermination: true,
341+
encrypted: true,
342+
volumeType: EbsDeviceVolumeType.IO2,
343+
}),
344+
}],
345+
});
346+
}).toThrow(/ops property is required with volumeType: EbsDeviceVolumeType.IO1 and EbsDeviceVolumeType.IO2/);
311347
});
312348

313349
test('warning if iops without volumeType', () => {
@@ -327,12 +363,10 @@ describe('instance', () => {
327363

328364
// THEN
329365
expect(instance.node.metadataEntry[0].type).toEqual(cxschema.ArtifactMetadataEntryType.WARN);
330-
expect(instance.node.metadataEntry[0].data).toEqual('iops will be ignored without volumeType: EbsDeviceVolumeType.IO1');
331-
332-
366+
expect(instance.node.metadataEntry[0].data).toEqual('iops will be ignored without volumeType: IO1, IO2, or GP3');
333367
});
334368

335-
test('warning if iops and volumeType !== IO1', () => {
369+
test('warning if iops and invalid volumeType', () => {
336370
const instance = new Instance(stack, 'Instance', {
337371
vpc,
338372
machineImage: new AmazonLinuxImage(),
@@ -350,9 +384,7 @@ describe('instance', () => {
350384

351385
// THEN
352386
expect(instance.node.metadataEntry[0].type).toEqual(cxschema.ArtifactMetadataEntryType.WARN);
353-
expect(instance.node.metadataEntry[0].data).toEqual('iops will be ignored without volumeType: EbsDeviceVolumeType.IO1');
354-
355-
387+
expect(instance.node.metadataEntry[0].data).toEqual('iops will be ignored without volumeType: IO1, IO2, or GP3');
356388
});
357389
});
358390

0 commit comments

Comments
 (0)