diff --git a/packages/aws-cdk-lib/aws-efs/lib/efs-file-system.ts b/packages/aws-cdk-lib/aws-efs/lib/efs-file-system.ts index 5c7811aa3f139..95bd3db05dda6 100644 --- a/packages/aws-cdk-lib/aws-efs/lib/efs-file-system.ts +++ b/packages/aws-cdk-lib/aws-efs/lib/efs-file-system.ts @@ -361,13 +361,6 @@ export interface FileSystemAttributes { * Replication configuration for the file system. */ export interface ReplicationConfiguration { - /** - * Whether to enable automatic replication. - * - * Other replication settings(`destinationFileSystem`, `kmsKey`, `region`, `az`) cannot be set if this is set to false. - */ - readonly enable: boolean; - /** * The existing destination file system for the replication. * @@ -606,8 +599,8 @@ export class FileSystem extends FileSystemBase { throw new Error('ThroughputMode ELASTIC is not supported for file systems with performanceMode MAX_IO'); } - const { destinationFileSystem, region, availabilityZone, kmsKey, enable } = props.replicationConfiguration ?? {}; - if (enable) { + const { destinationFileSystem, region, availabilityZone, kmsKey } = props.replicationConfiguration ?? {}; + if (props.replicationConfiguration) { if (props.replicationOverwriteProtection === ReplicationOverwriteProtection.DISABLED) { throw new Error('Cannot configure `replicationConfiguration` when `replicationOverwriteProtection` is set to `DISABLED`'); } @@ -619,10 +612,10 @@ export class FileSystem extends FileSystemBase { if (region && !Token.isUnresolved(region) && !/^[a-z]{2}-((iso[a-z]{0,1}-)|(gov-)){0,1}[a-z]+-{0,1}[0-9]{0,1}$/.test(region)) { throw new Error('`replicationConfiguration.region` is invalid.'); } - } - if (enable === false && (destinationFileSystem || region || availabilityZone || kmsKey)) { - throw new Error('Cannot configure replication when `replicationConfiguration.enableReplication` is set to `false`'); + if (availabilityZone && !Token.isUnresolved(availabilityZone) && !region) { + throw new Error('`replicationConfiguration.availabilityZone` cannot be specified without `replicationConfiguration.region`'); + } } // we explictly use 'undefined' to represent 'false' to maintain backwards compatibility since @@ -651,12 +644,12 @@ export class FileSystem extends FileSystemBase { replicationOverwriteProtection: props.replicationOverwriteProtection, } : undefined; - const replicationConfiguration = enable ? { + const replicationConfiguration = props.replicationConfiguration ? { destinations: [ { fileSystemId: destinationFileSystem?.fileSystemId, kmsKeyId: kmsKey?.keyArn, - region: destinationFileSystem ? destinationFileSystem.env.region : (region ?? Stack.of(this).region) + region: destinationFileSystem ? destinationFileSystem.env.region : (region ?? Stack.of(this).region), availabilityZoneName: availabilityZone, }, ], diff --git a/packages/aws-cdk-lib/aws-efs/test/efs-file-system.test.ts b/packages/aws-cdk-lib/aws-efs/test/efs-file-system.test.ts index fc3381cd828ba..2d65149667a18 100644 --- a/packages/aws-cdk-lib/aws-efs/test/efs-file-system.test.ts +++ b/packages/aws-cdk-lib/aws-efs/test/efs-file-system.test.ts @@ -964,9 +964,7 @@ describe('replication configuration', () => { // WHEN new FileSystem(stack, 'EfsFileSystem', { vpc, - replicationConfiguration: { - enable: true, - }, + replicationConfiguration: {}, }); // THEN @@ -993,7 +991,6 @@ describe('replication configuration', () => { vpc, replicationConfiguration: { destinationFileSystem: destination, - enable: true, }, }); @@ -1016,7 +1013,6 @@ describe('replication configuration', () => { new FileSystem(stack, 'EfsFileSystem', { vpc, replicationConfiguration: { - enable: true, kmsKey: new kms.Key(stack, 'customKey'), region: 'us-east-1', availabilityZone: 'us-east-1a', @@ -1048,7 +1044,7 @@ describe('replication configuration', () => { new FileSystem(stack, 'EfsFileSystem', { vpc, replicationConfiguration: { - enable: true, + region: 'us-east-1', }, replicationOverwriteProtection: ReplicationOverwriteProtection.DISABLED, }); @@ -1071,7 +1067,6 @@ describe('replication configuration', () => { vpc, replicationConfiguration: { destinationFileSystem: destination, - enable: true, ...config, }, }); @@ -1091,71 +1086,34 @@ describe('replication configuration', () => { vpc, replicationConfiguration: { destinationFileSystem: destination, - enable: true, kmsKey: new kms.Key(stack, 'customKey'), }, }); }).toThrow('Cannot configure `replicationConfiguration.region`, `replicationConfiguration.az` or `replicationConfiguration.kmsKey` when `replicationConfiguration.destinationFileSystem` is set'); }); - test.each([ - { region: 'us-east-1' }, - { availabilityZone: 'us-east-1a' }, - ])('throw error when configure replication settings for replication disabled file system', (config) => { - // THEN - expect(() => { - new FileSystem(stack, 'EfsFileSystem', { - vpc, - replicationConfiguration: { - enable: false, - ...config, - }, - }); - }).toThrow('Cannot configure replication when `replicationConfiguration.enableReplication` is set to `false`'); - }); - - test('throw error when configure kmsKey for replication disabled file system', () => { - // THEN - expect(() => { - new FileSystem(stack, 'EfsFileSystem', { - vpc, - replicationConfiguration: { - enable: false, - kmsKey: new kms.Key(stack, 'customKey'), - }, - }); - }).toThrow('Cannot configure replication when `replicationConfiguration.enableReplication` is set to `false`'); - }); - - test('throw error when configure destinationFileSystem for replication disabled file system', () => { - // WHEN - const destination = new FileSystem(stack, 'DestinationFileSystem', { - vpc, - replicationOverwriteProtection: ReplicationOverwriteProtection.DISABLED, - }); - + test('throw error for invalid region', () => { // THEN expect(() => { new FileSystem(stack, 'EfsFileSystem', { vpc, replicationConfiguration: { - enable: false, - destinationFileSystem: destination, + enable: true, + region: 'invalid-region', }, }); - }).toThrow('Cannot configure replication when `replicationConfiguration.enableReplication` is set to `false`'); + }).toThrow('`replicationConfiguration.region` is invalid.'); }); - test('throw error for invalid region', () => { + test('throw error for specifying availabilityZone without region', () => { // THEN expect(() => { new FileSystem(stack, 'EfsFileSystem', { vpc, replicationConfiguration: { - enable: true, - region: 'invalid-region', + availabilityZone: 'us-east-1a', }, }); - }).toThrow('`replicationConfiguration.region` is invalid.'); + }).toThrow('`replicationConfiguration.availabilityZone` cannot be specified without `replicationConfiguration.region`'); }); });