Skip to content

Commit

Permalink
feat(efs): add support for backup policy (#10524)
Browse files Browse the repository at this point in the history
Add support for setting `BackupPolicy` to the `FileSystem` L2 construct. [Reference](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-efs-filesystem.html#cfn-efs-filesystem-backuppolicy)

closes #10414 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
ayush987goyal authored Oct 7, 2020
1 parent 4864fa0 commit 41f6de2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-efs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ const fileSystem = new efs.FileSystem(this, 'MyEfsFileSystem', {
encrypted: true,
lifecyclePolicy: efs.LifecyclePolicy.AFTER_14_DAYS,
performanceMode: efs.PerformanceMode.GENERAL_PURPOSE,
throughputMode: efs.ThroughputMode.BURSTING
throughputMode: efs.ThroughputMode.BURSTING,
enableAutomaticBackups: true
});

const inst = new Instance(this, 'inst', {
Expand Down
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-efs/lib/efs-file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ export interface FileSystemProps {
* @default RemovalPolicy.RETAIN
*/
readonly removalPolicy?: RemovalPolicy;

/**
* Whether to enable automatic backups for the file system.
*
* @default false
*/
readonly enableAutomaticBackups?: boolean;
}

/**
Expand Down Expand Up @@ -252,6 +259,7 @@ export class FileSystem extends Resource implements IFileSystem {
performanceMode: props.performanceMode,
throughputMode: props.throughputMode,
provisionedThroughputInMibps: props.provisionedThroughputPerSecond?.toMebibytes(),
backupPolicy: props.enableAutomaticBackups ? { status: 'ENABLED' } : undefined,
});
filesystem.applyRemovalPolicy(props.removalPolicy);

Expand Down
15 changes: 14 additions & 1 deletion packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FileSystem, LifecyclePolicy, PerformanceMode, ThroughputMode } from '..
let stack = new Stack();
let vpc = new ec2.Vpc(stack, 'VPC');

beforeEach( () => {
beforeEach(() => {
stack = new Stack();
vpc = new ec2.Vpc(stack, 'VPC');
});
Expand Down Expand Up @@ -216,11 +216,24 @@ test('auto-named if none provided', () => {
});

test('removalPolicy is DESTROY', () => {
// WHEN
new FileSystem(stack, 'EfsFileSystem', { vpc, removalPolicy: RemovalPolicy.DESTROY });

// THEN
expectCDK(stack).to(haveResource('AWS::EFS::FileSystem', {
DeletionPolicy: 'Delete',
UpdateReplacePolicy: 'Delete',
}, ResourcePart.CompleteDefinition));
});

test('can specify backup policy', () => {
// WHEN
new FileSystem(stack, 'EfsFileSystem', { vpc, enableAutomaticBackups: true });

// THEN
expectCDK(stack).to(haveResource('AWS::EFS::FileSystem', {
BackupPolicy: {
Status: 'ENABLED',
},
}));
});

0 comments on commit 41f6de2

Please sign in to comment.