Skip to content

Commit f43b4d4

Browse files
rsmoguraElad Ben-Israel
authored andcommitted
feat(aws-kms): allow tagging kms keys (#1485)
Small change to enable tagging KMS keys.
1 parent 82ec0ff commit f43b4d4

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

packages/@aws-cdk/aws-kms/lib/key.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PolicyDocument, PolicyStatement } from '@aws-cdk/aws-iam';
2-
import { Construct, DeletionPolicy, IConstruct, Output, resolve } from '@aws-cdk/cdk';
2+
import { Construct, DeletionPolicy, IConstruct, Output, resolve, TagManager, Tags } from '@aws-cdk/cdk';
33
import { EncryptionKeyAlias } from './alias';
44
import { CfnKey } from './kms.generated';
55

@@ -106,6 +106,11 @@ export interface EncryptionKeyProps {
106106
* administer the key will be created.
107107
*/
108108
policy?: PolicyDocument;
109+
110+
/**
111+
* The AWS resource tags to associate with the KMS key.
112+
*/
113+
tags?: Tags;
109114
}
110115

111116
/**
@@ -134,6 +139,11 @@ export class EncryptionKey extends EncryptionKeyBase {
134139
return new ImportedEncryptionKey(scope, id, props);
135140
}
136141

142+
/**
143+
* Manage tags for this construct and children
144+
*/
145+
public readonly tags: TagManager;
146+
137147
public readonly keyArn: string;
138148
protected readonly policy?: PolicyDocument;
139149

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

160+
this.tags = new TagManager(this, { initialTags: props.tags });
161+
150162
const resource = new CfnKey(this, 'Resource', {
151163
description: props.description,
152164
enableKeyRotation: props.enableKeyRotation,
153165
enabled: props.enabled,
154-
keyPolicy: this.policy
166+
keyPolicy: this.policy,
167+
tags: this.tags
155168
});
156169

157170
this.keyArn = resource.keyArn;

packages/@aws-cdk/aws-kms/test/test.key.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ export = {
143143

144144
const key = new EncryptionKey(stack, 'MyKey', {
145145
enableKeyRotation: true,
146-
enabled: false
146+
enabled: false,
147+
tags: {
148+
tag1: 'value1',
149+
tag2: 'value2',
150+
tag3: ''
151+
}
147152
});
148153
const p = new PolicyStatement().addAllResources().addAction('kms:encrypt');
149154
p.addAwsPrincipal('arn');
@@ -204,7 +209,21 @@ export = {
204209
}
205210
],
206211
Version: "2012-10-17"
207-
}
212+
},
213+
Tags: [
214+
{
215+
Key: "tag1",
216+
Value: "value1"
217+
},
218+
{
219+
Key: "tag2",
220+
Value: "value2"
221+
},
222+
{
223+
Key: "tag3",
224+
Value: ""
225+
}
226+
]
208227
},
209228
DeletionPolicy: "Retain"
210229
}

0 commit comments

Comments
 (0)