From f78c3469522006d38078db6effc4556d44da9747 Mon Sep 17 00:00:00 2001 From: Robert Djurasaj Date: Mon, 10 Aug 2020 07:14:47 -0600 Subject: [PATCH] fix(efs): LifecyclePolicy of AFTER_7_DAYS is not applied (#9475) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #9474 (see for details). ```ts const fileSystem = new efs.FileSystem(this, "EFS", { removalPolicy: cdk.RemovalPolicy.DESTROY, lifecyclePolicy: efs.LifecyclePolicy.AFTER_7_DAYS, vpc, }); ``` Old behavior: ```bash npm run build; cdk synth | grep -r -n1 "AFTER_"; cdk diff > demo@0.1.0 build /Users/robertd/code/demo > tsc Stack EFSDemoTest Resources [~] AWS::EFS::FileSystem EFS EFSBAA8953A └─ [-] LifecyclePolicies └─ [{"TransitionToIA":"AFTER_14_DAYS"}] ``` **New (expected) behavior:** 🎆 🥳 🍾 ```bash npm run build; cdk synth | grep -r -n1 "AFTER_"; cdk diff > demo@0.1.0 build /Users/robertd/demo > tsc (standard input)-327- LifecyclePolicies: (standard input):328: - TransitionToIA: AFTER_7_DAYS (standard input)-329- UpdateReplacePolicy: Delete Stack EFSDemoTest Resources [~] AWS::EFS::FileSystem EFS EFSBAA8953A └─ [~] LifecyclePolicies └─ @@ -1,5 +1,5 @@ [ ] [ [ ] { [-] "TransitionToIA": "AFTER_14_DAYS" [+] "TransitionToIA": "AFTER_7_DAYS" [ ] } [ ] ] ``` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-efs/README.md | 2 +- packages/@aws-cdk/aws-efs/lib/efs-file-system.ts | 14 ++++++-------- .../@aws-cdk/aws-efs/test/efs-file-system.test.ts | 6 +++--- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/@aws-cdk/aws-efs/README.md b/packages/@aws-cdk/aws-efs/README.md index 01d766117a6b1..f1082eeddbc83 100644 --- a/packages/@aws-cdk/aws-efs/README.md +++ b/packages/@aws-cdk/aws-efs/README.md @@ -68,7 +68,7 @@ fileSystem.connections.allowDefaultPortFrom(instance); In order to automatically mount this file system during instance launch, following code can be used as reference: -``` +```ts const vpc = new ec2.Vpc(this, 'VPC'); const fileSystem = new efs.FileSystem(this, 'MyEfsFileSystem', { diff --git a/packages/@aws-cdk/aws-efs/lib/efs-file-system.ts b/packages/@aws-cdk/aws-efs/lib/efs-file-system.ts index 8103ee40bae79..854503f388f7d 100644 --- a/packages/@aws-cdk/aws-efs/lib/efs-file-system.ts +++ b/packages/@aws-cdk/aws-efs/lib/efs-file-system.ts @@ -13,27 +13,27 @@ export enum LifecyclePolicy { /** * After 7 days of not being accessed. */ - AFTER_7_DAYS, + AFTER_7_DAYS = 'AFTER_7_DAYS', /** * After 14 days of not being accessed. */ - AFTER_14_DAYS, + AFTER_14_DAYS = 'AFTER_14_DAYS', /** * After 30 days of not being accessed. */ - AFTER_30_DAYS, + AFTER_30_DAYS = 'AFTER_30_DAYS', /** * After 60 days of not being accessed. */ - AFTER_60_DAYS, + AFTER_60_DAYS = 'AFTER_60_DAYS', /** * After 90 days of not being accessed. */ - AFTER_90_DAYS + AFTER_90_DAYS = 'AFTER_90_DAYS' } /** @@ -247,9 +247,7 @@ export class FileSystem extends Resource implements IFileSystem { const filesystem = new CfnFileSystem(this, 'Resource', { encrypted: props.encrypted, kmsKeyId: (props.kmsKey ? props.kmsKey.keyId : undefined), - lifecyclePolicies: (props.lifecyclePolicy ? Array.of({ - transitionToIa: LifecyclePolicy[props.lifecyclePolicy], - } as CfnFileSystem.LifecyclePolicyProperty) : undefined), + lifecyclePolicies: (props.lifecyclePolicy ? [{ transitionToIa: props.lifecyclePolicy }] : undefined), performanceMode: props.performanceMode, throughputMode: props.throughputMode, provisionedThroughputInMibps: props.provisionedThroughputPerSecond?.toMebibytes(), diff --git a/packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts b/packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts index 42fa89ee8d9ae..5104c069ec061 100644 --- a/packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts +++ b/packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts @@ -75,16 +75,16 @@ test('encrypted file system is created correctly with custom KMS', () => { })); }); -test('file system is created correctly with life cycle property', () => { +test('file system is created correctly with a life cycle property', () => { // WHEN new FileSystem(stack, 'EfsFileSystem', { vpc, - lifecyclePolicy: LifecyclePolicy.AFTER_14_DAYS, + lifecyclePolicy: LifecyclePolicy.AFTER_7_DAYS, }); // THEN expectCDK(stack).to(haveResource('AWS::EFS::FileSystem', { LifecyclePolicies: [{ - TransitionToIA: 'AFTER_14_DAYS', + TransitionToIA: 'AFTER_7_DAYS', }], })); });