Skip to content

Commit

Permalink
fix(efs): LifecyclePolicy of AFTER_7_DAYS is not applied (#9475)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
robertd authored Aug 10, 2020
1 parent 5c01da8 commit f78c346
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-efs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
14 changes: 6 additions & 8 deletions packages/@aws-cdk/aws-efs/lib/efs-file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

/**
Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}],
}));
});
Expand Down

0 comments on commit f78c346

Please sign in to comment.