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

feat(aws-kms): allow tagging kms keys #1485

Merged
merged 1 commit into from
Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 15 additions & 2 deletions packages/@aws-cdk/aws-kms/lib/key.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PolicyDocument, PolicyStatement } from '@aws-cdk/aws-iam';
import { Construct, DeletionPolicy, IConstruct, Output, resolve } from '@aws-cdk/cdk';
import { Construct, DeletionPolicy, IConstruct, Output, resolve, TagManager, Tags } from '@aws-cdk/cdk';
import { EncryptionKeyAlias } from './alias';
import { CfnKey } from './kms.generated';

Expand Down Expand Up @@ -106,6 +106,11 @@ export interface EncryptionKeyProps {
* administer the key will be created.
*/
policy?: PolicyDocument;

/**
* The AWS resource tags to associate with the KMS key.
*/
tags?: Tags;
}

/**
Expand Down Expand Up @@ -134,6 +139,11 @@ export class EncryptionKey extends EncryptionKeyBase {
return new ImportedEncryptionKey(scope, id, props);
}

/**
* Manage tags for this construct and children
*/
public readonly tags: TagManager;

public readonly keyArn: string;
protected readonly policy?: PolicyDocument;

Expand All @@ -147,11 +157,14 @@ export class EncryptionKey extends EncryptionKeyBase {
this.allowAccountToAdmin();
}

this.tags = new TagManager(this, { initialTags: props.tags });

const resource = new CfnKey(this, 'Resource', {
description: props.description,
enableKeyRotation: props.enableKeyRotation,
enabled: props.enabled,
keyPolicy: this.policy
keyPolicy: this.policy,
tags: this.tags
});

this.keyArn = resource.keyArn;
Expand Down
23 changes: 21 additions & 2 deletions packages/@aws-cdk/aws-kms/test/test.key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ export = {

const key = new EncryptionKey(stack, 'MyKey', {
enableKeyRotation: true,
enabled: false
enabled: false,
tags: {
tag1: 'value1',
tag2: 'value2',
tag3: ''
}
});
const p = new PolicyStatement().addAllResources().addAction('kms:encrypt');
p.addAwsPrincipal('arn');
Expand Down Expand Up @@ -204,7 +209,21 @@ export = {
}
],
Version: "2012-10-17"
}
},
Tags: [
{
Key: "tag1",
Value: "value1"
},
{
Key: "tag2",
Value: "value2"
},
{
Key: "tag3",
Value: ""
}
]
},
DeletionPolicy: "Retain"
}
Expand Down