Skip to content

Commit 0b1ea76

Browse files
authored
fix(logs): fix infinite retention for jsii users (#3250)
The retention period was still accepting the value `Infinity` for "infinite retention", even though the property has been changed to an enum instead of `number`. Even though this apparently works for TypeScript customers, jsii customers will not be able to pass in a number where an enum value is expected, and so won't be able to configure infinite retention. Add an `INFINITE` value to the enum.
1 parent f68411c commit 0b1ea76

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

Diff for: packages/@aws-cdk/aws-logs/lib/log-group.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,12 @@ export enum RetentionDays {
259259
/**
260260
* 10 years
261261
*/
262-
TEN_YEARS = 3653
262+
TEN_YEARS = 3653,
263+
264+
/**
265+
* Retain logs forever
266+
*/
267+
INFINITE = 9999,
263268
}
264269

265270
/**
@@ -276,9 +281,9 @@ export interface LogGroupProps {
276281
/**
277282
* How long, in days, the log contents will be retained.
278283
*
279-
* To retain all logs, set this value to Infinity.
284+
* To retain all logs, set this value to RetentionDays.INFINITE.
280285
*
281-
* @default RetentionDays.TwoYears
286+
* @default RetentionDays.TWO_YEARS
282287
*/
283288
readonly retention?: RetentionDays;
284289

@@ -328,7 +333,7 @@ export class LogGroup extends LogGroupBase {
328333

329334
let retentionInDays = props.retention;
330335
if (retentionInDays === undefined) { retentionInDays = RetentionDays.TWO_YEARS; }
331-
if (retentionInDays === Infinity) { retentionInDays = undefined; }
336+
if (retentionInDays === Infinity || retentionInDays === RetentionDays.INFINITE) { retentionInDays = undefined; }
332337

333338
if (retentionInDays !== undefined && retentionInDays <= 0) {
334339
throw new Error(`retentionInDays must be positive, got ${retentionInDays}`);

Diff for: packages/@aws-cdk/aws-logs/test/test.loggroup.ts

+26
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,32 @@ export = {
4343

4444
// WHEN
4545
new LogGroup(stack, 'LogGroup', {
46+
retention: RetentionDays.INFINITE,
47+
});
48+
49+
// THEN
50+
expect(stack).to(matchTemplate({
51+
Resources: {
52+
LogGroupF5B46931: {
53+
Type: "AWS::Logs::LogGroup",
54+
DeletionPolicy: "Retain",
55+
UpdateReplacePolicy: "Retain"
56+
}
57+
}
58+
}));
59+
60+
test.done();
61+
},
62+
63+
'infinite retention via legacy method'(test: Test) {
64+
// GIVEN
65+
const stack = new Stack();
66+
67+
// WHEN
68+
new LogGroup(stack, 'LogGroup', {
69+
// Don't know why TypeScript doesn't complain about passing Infinity to
70+
// something where an enum is expected, but better keep this behavior for
71+
// existing clients.
4672
retention: Infinity
4773
});
4874

0 commit comments

Comments
 (0)