diff --git a/packages/aws-cdk-lib/aws-ec2/lib/volume.ts b/packages/aws-cdk-lib/aws-ec2/lib/volume.ts index 57a2b6ae5cf48..70d19b119f717 100644 --- a/packages/aws-cdk-lib/aws-ec2/lib/volume.ts +++ b/packages/aws-cdk-lib/aws-ec2/lib/volume.ts @@ -3,8 +3,9 @@ import { CfnVolume } from './ec2.generated'; import { IInstance } from './instance'; import { AccountRootPrincipal, Grant, IGrantable } from '../../aws-iam'; import { IKey, ViaServicePrincipal } from '../../aws-kms'; -import { IResource, Resource, Size, SizeRoundingBehavior, Stack, Token, Tags, Names, RemovalPolicy } from '../../core'; +import { IResource, Resource, Size, SizeRoundingBehavior, Stack, Token, Tags, Names, RemovalPolicy, FeatureFlags } from '../../core'; import { md5hash } from '../../core/lib/helpers-internal'; +import * as cxapi from '../../cx-api'; /** * Block device @@ -65,7 +66,8 @@ export interface EbsDeviceOptionsBase { * The EBS volume type * @see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html * - * @default `EbsDeviceVolumeType.GP2` + * @default `EbsDeviceVolumeType.GENERAL_PURPOSE_SSD` or `EbsDeviceVolumeType.GENERAL_PURPOSE_SSD_GP3` if + * `@aws-cdk/aws-ec2:ebsDefaultGp3Volume` is enabled. */ readonly volumeType?: EbsDeviceVolumeType; } @@ -621,7 +623,9 @@ export class Volume extends VolumeBase { size: props.size?.toGibibytes({ rounding: SizeRoundingBehavior.FAIL }), snapshotId: props.snapshotId, throughput: props.throughput, - volumeType: props.volumeType ?? EbsDeviceVolumeType.GENERAL_PURPOSE_SSD, + volumeType: props.volumeType ?? + (FeatureFlags.of(this).isEnabled(cxapi.EBS_DEFAULT_GP3) ? + EbsDeviceVolumeType.GENERAL_PURPOSE_SSD_GP3 : EbsDeviceVolumeType.GENERAL_PURPOSE_SSD), }); resource.applyRemovalPolicy(props.removalPolicy); diff --git a/packages/aws-cdk-lib/aws-ec2/test/volume.test.ts b/packages/aws-cdk-lib/aws-ec2/test/volume.test.ts index cce55f2497bc8..612555a544c3c 100644 --- a/packages/aws-cdk-lib/aws-ec2/test/volume.test.ts +++ b/packages/aws-cdk-lib/aws-ec2/test/volume.test.ts @@ -2,6 +2,7 @@ import { Match, Template } from '../../assertions'; import { AccountRootPrincipal, Role } from '../../aws-iam'; import * as kms from '../../aws-kms'; import * as cdk from '../../core'; +import * as cxapi from '../../cx-api'; import { AmazonLinuxGeneration, EbsDeviceVolumeType, @@ -457,6 +458,23 @@ describe('volume', () => { }); }); + test('EBS_DEFAULT_GP3 feature flag', () => { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + stack.node.setContext(cxapi.EBS_DEFAULT_GP3, true); + new Volume(stack, 'Volume', { + availabilityZone: 'us-east-1a', + size: cdk.Size.gibibytes(500), + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::EC2::Volume', { + VolumeType: 'gp3', + }); + }); + describe('grantAttachVolume to any instance with encryption', () => { test('with default key policies', () => { // GIVEN diff --git a/packages/aws-cdk-lib/cx-api/FEATURE_FLAGS.md b/packages/aws-cdk-lib/cx-api/FEATURE_FLAGS.md index 4eb649762d4ba..47cd7365475b3 100644 --- a/packages/aws-cdk-lib/cx-api/FEATURE_FLAGS.md +++ b/packages/aws-cdk-lib/cx-api/FEATURE_FLAGS.md @@ -67,7 +67,8 @@ Flags come in three types: | [@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse](#aws-cdkaws-codepipelinecrossaccountkeysdefaultvaluetofalse) | Enables Pipeline to set the default value for crossAccountKeys to false. | 2.127.0 | (default) | | [@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2](#aws-cdkaws-codepipelinedefaultpipelinetypetov2) | Enables Pipeline to set the default pipeline type to V2. | 2.133.0 | (default) | | [@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope](#aws-cdkaws-kmsreducecrossaccountregionpolicyscope) | When enabled, IAM Policy created from KMS key grant will reduce the resource scope to this key only. | 2.134.0 | (fix) | -| [@aws-cdk/aws-eks:nodegroupNameAttribute](#aws-cdkaws-eksnodegroupnameattribute) | When enabled, nodegroupName attribute of the provisioned EKS NodeGroup will not have the cluster name prefix. | 2.139.0 | (fix) | +| [@aws-cdk/aws-eks:nodegroupNameAttribute](#aws-cdkaws-eksnodegroupnameattribute) | When enabled, nodegroupName attribute of the managed EKS NodeGroup will not have the cluster name prefix. | 2.138.0 | (fix) | +| [@aws-cdk/aws-ec2:ebsDefaultGp3Volume](#aws-cdkaws-ec2ebsdefaultgp3volume) | When enabled, the default volume type of the EBS volume will be GP3 | 2.139.0 | (default) | @@ -126,7 +127,8 @@ The following json shows the current recommended set of flags, as `cdk init` wou "@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true, "@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": true, "@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true, - "@aws-cdk/aws-eks:nodegroupNameAttribute": true + "@aws-cdk/aws-eks:nodegroupNameAttribute": true, + "@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true } } ``` @@ -1280,5 +1282,18 @@ any prefix. | (not in v1) | | | | 2.139.0 | `false` | `true` | +### @aws-cdk/aws-ec2:ebsDefaultGp3Volume + +*When enabled, the default volume type of the EBS volume will be GP3* (default) + +When this featuer flag is enabled, the default volume type of the EBS volume will be `EbsDeviceVolumeType.GENERAL_PURPOSE_SSD_GP3`. + + +| Since | Default | Recommended | +| ----- | ----- | ----- | +| (not in v1) | | | +| 2.139.0 | `false` | `true` | + +**Compatibility with old behavior:** Pass `volumeType: EbsDeviceVolumeType.GENERAL_PURPOSE_SSD` to `Volume` construct to restore the previous behavior. diff --git a/packages/aws-cdk-lib/cx-api/README.md b/packages/aws-cdk-lib/cx-api/README.md index 17134308a606a..5862a3016db16 100644 --- a/packages/aws-cdk-lib/cx-api/README.md +++ b/packages/aws-cdk-lib/cx-api/README.md @@ -326,3 +326,19 @@ _cdk.json_ } } ``` + +* `@aws-cdk/aws-ec2:ebsDefaultGp3Volume` + +When enabled, the default volume type of the EBS volume will be GP3. + +When this featuer flag is enabled, the default volume type of the EBS volume will be `EbsDeviceVolumeType.GENERAL_PURPOSE_SSD_GP3` + +_cdk.json_ + +```json +{ + "context": { + "@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true + } +} +``` diff --git a/packages/aws-cdk-lib/cx-api/lib/features.ts b/packages/aws-cdk-lib/cx-api/lib/features.ts index 10d48e80147af..1f6e6d3587279 100644 --- a/packages/aws-cdk-lib/cx-api/lib/features.ts +++ b/packages/aws-cdk-lib/cx-api/lib/features.ts @@ -102,6 +102,7 @@ export const CODEPIPELINE_CROSS_ACCOUNT_KEYS_DEFAULT_VALUE_TO_FALSE = '@aws-cdk/ export const CODEPIPELINE_DEFAULT_PIPELINE_TYPE_TO_V2 = '@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2'; export const KMS_REDUCE_CROSS_ACCOUNT_REGION_POLICY_SCOPE = '@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope'; export const EKS_NODEGROUP_NAME = '@aws-cdk/aws-eks:nodegroupNameAttribute'; +export const EBS_DEFAULT_GP3 = '@aws-cdk/aws-ec2:ebsDefaultGp3Volume'; export const FLAGS: Record = { ////////////////////////////////////////////////////////////////////// @@ -1047,6 +1048,18 @@ export const FLAGS: Record = { introducedIn: { v2: '2.139.0' }, recommendedValue: true, }, + + ////////////////////////////////////////////////////////////////////// + [EBS_DEFAULT_GP3]: { + type: FlagType.ApiDefault, + summary: 'When enabled, the default volume type of the EBS volume will be GP3', + detailsMd: ` + When this featuer flag is enabled, the default volume type of the EBS volume will be \`EbsDeviceVolumeType.GENERAL_PURPOSE_SSD_GP3\`. + `, + introducedIn: { v2: 'V2NEXT' }, + recommendedValue: true, + compatibilityWithOldBehaviorMd: 'Pass `volumeType: EbsDeviceVolumeType.GENERAL_PURPOSE_SSD` to `Volume` construct to restore the previous behavior.', + }, }; const CURRENT_MV = 'v2';