Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(efs): support tagging + filesystem naming #7363

Merged
merged 3 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/@aws-cdk/aws-efs/lib/efs-file-system.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ec2 from '@aws-cdk/aws-ec2';
import * as kms from '@aws-cdk/aws-kms';
import {Construct, Resource} from '@aws-cdk/core';
import {Construct, Resource, Tag} from '@aws-cdk/core';
import {CfnFileSystem, CfnMountTarget} from './efs.generated';

// tslint:disable: max-line-length
Expand Down Expand Up @@ -114,6 +114,13 @@ export interface EfsFileSystemProps {
*/
readonly encrypted?: boolean;

/**
* The filesystem's name.
*
* @default - CDK generated name
*/
readonly fileSystemName?: string;

/**
* The KMS key used for encryption. This is required to encrypt the data at rest if @encrypted is set to true.
*
Expand Down Expand Up @@ -255,6 +262,7 @@ export class EfsFileSystem extends EfsFileSystemBase {

this.fileSystemId = this.efsFileSystem.ref;
this.node.defaultChild = this.efsFileSystem;
Tag.add(this, 'Name', props.fileSystemName || this.node.path);

const securityGroup = (props.securityGroup || new ec2.SecurityGroup(this, 'EfsSecurityGroup', {
vpc: props.vpc
Expand Down
48 changes: 46 additions & 2 deletions packages/@aws-cdk/aws-efs/test/efs-file-system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {expect as expectCDK, haveResource} from '@aws-cdk/assert';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as kms from '@aws-cdk/aws-kms';
import * as cxschema from '@aws-cdk/cloud-assembly-schema';
import {Stack} from '@aws-cdk/core';
import {Stack, Tag} from '@aws-cdk/core';
import {EfsFileSystem, EfsLifecyclePolicyProperty, EfsPerformanceMode, EfsThroughputMode} from '../lib/efs-file-system';

let stack = new Stack();
Expand Down Expand Up @@ -187,4 +187,48 @@ test('existing file system is imported correctly', () => {
expectCDK(stack).to(haveResource('AWS::EC2::SecurityGroupEgress', {
GroupId: 'sg-123456789',
}));
});
});

test('support tags', () => {
// WHEN
const fileSystem = new EfsFileSystem(stack, 'EfsFileSystem', {
vpc,
});
Tag.add(fileSystem, 'Name', 'LookAtMeAndMyFancyTags');

// THEN
expectCDK(stack).to(haveResource('AWS::EFS::FileSystem', {
FileSystemTags: [
{Key: 'Name', Value: 'LookAtMeAndMyFancyTags'}
]
}));
});

test('file system is created correctly when given a name', () => {
// WHEN
new EfsFileSystem(stack, 'EfsFileSystem', {
fileSystemName: 'MyNameableFileSystem',
vpc,
});

// THEN
expectCDK(stack).to(haveResource('AWS::EFS::FileSystem', {
FileSystemTags: [
{Key: 'Name', Value: 'MyNameableFileSystem'}
]
}));
});

test('auto-named if none provided', () => {
// WHEN
const fileSystem = new EfsFileSystem(stack, 'EfsFileSystem', {
vpc,
});

// THEN
expectCDK(stack).to(haveResource('AWS::EFS::FileSystem', {
FileSystemTags: [
{Key: 'Name', Value: fileSystem.node.path}
]
}));
});
6 changes: 4 additions & 2 deletions packages/@aws-cdk/cfnspec/lib/schema/property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export interface ComplexMapProperty extends MapPropertyBase {
}

export interface TagPropertyStandard extends PropertyBase {
ItemType: 'Tag' | 'TagsEntry' | 'TagRef';
ItemType: 'Tag' | 'TagsEntry' | 'TagRef' | 'ElasticFileSystemTag';
Type: 'Tags';
}

Expand Down Expand Up @@ -223,6 +223,7 @@ export function isPropertyScrutinyType(str: string): str is PropertyScrutinyType
}

const tagPropertyNames = {
FileSystemTags: '',
Tags: '',
UserPoolTags: '',
};
Expand Down Expand Up @@ -255,7 +256,8 @@ export function isTagPropertyStandard(prop: Property): prop is TagPropertyStanda
(prop as TagPropertyStandard).ItemType === 'Tag' ||
(prop as TagPropertyStandard).ItemType === 'TagsEntry' ||
(prop as TagPropertyStandard).Type === 'Tags' ||
(prop as TagPropertyStandard).ItemType === 'TagRef'
(prop as TagPropertyStandard).ItemType === 'TagRef' ||
(prop as TagPropertyStandard).ItemType === 'ElasticFileSystemTag'
);

}
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/cfnspec/lib/schema/resource-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface ResourceType extends Documented {

export interface TaggableResource extends ResourceType {
Properties: {
FileSystemTags: TagProperty;
Tags: TagProperty;
UserPoolTags: TagProperty;
[name: string]: Property;
Expand Down