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(logs): DataProtectionPolicy not displaying properly in console #31725

Closed
wants to merge 9 commits into from

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@
"Type": "AWS::Logs::LogGroup",
"Properties": {
"DataProtectionPolicy": {
"name": "policy-name",
"description": "policy description",
"version": "2021-06-01",
"configuration": {
"customDataIdentifier": [
{
"name": "EmployeeId",
"regex": "EmployeeId-\\d{9}"
}
]
},
"statement": [
"Name": "policy-name",
"Description": "policy description",
"Version": "2021-06-01",
"Statement": [
{
"sid": "audit-statement-cdk",
"dataIdentifier": [
Expand Down Expand Up @@ -110,7 +102,15 @@
}
}
}
]
],
"Configuration": {
"customDataIdentifier": [
{
"name": "EmployeeId",
"regex": "EmployeeId-\\d{9}"
}
]
}
},
"RetentionInDays": 731
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class LogGroupIntegStack extends Stack {

const dataProtectionPolicy = new DataProtectionPolicy({
name: 'policy-name',
description: 'policy description',
description: 'policy description example',
identifiers: [DataIdentifier.DRIVERSLICENSE_US, new DataIdentifier('EmailAddress'), new CustomDataIdentifier('EmployeeId', 'EmployeeId-\\d{9}')],
logGroupAuditDestination: audit,
s3BucketAuditDestination: bucket,
Expand Down
9 changes: 8 additions & 1 deletion packages/aws-cdk-lib/aws-logs/lib/log-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,12 +626,19 @@ export class LogGroup extends LogGroupBase {
Annotations.of(this).addWarningV2('@aws-cdk/aws-logs:propertyNotSupported', `The LogGroupClass property is not supported in the following regions: ${logGroupClassUnsupportedRegions}`);
}

const dataProtectionPolicy = props.dataProtectionPolicy?._bind(this) || null;
const resource = new CfnLogGroup(this, 'Resource', {
kmsKeyId: props.encryptionKey?.keyArn,
logGroupClass,
logGroupName: this.physicalName,
retentionInDays,
dataProtectionPolicy: props.dataProtectionPolicy?._bind(this),
dataProtectionPolicy: dataProtectionPolicy ? {
Name: dataProtectionPolicy?.name,
Description: dataProtectionPolicy?.description,
Version: dataProtectionPolicy?.version,
Statement: dataProtectionPolicy?.statement,
Configuration: dataProtectionPolicy?.configuration,
} : undefined,
});

resource.applyRemovalPolicy(props.removalPolicy);
Expand Down
44 changes: 22 additions & 22 deletions packages/aws-cdk-lib/aws-logs/test/loggroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,10 @@ describe('log group', () => {
Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogGroup', {
LogGroupName: logGroupName,
DataProtectionPolicy: {
name: 'test-policy-name',
description: 'test description',
version: '2021-06-01',
statement: [
Name: 'test-policy-name',
Description: 'test description',
Version: '2021-06-01',
Statement: [
{
sid: 'audit-statement-cdk',
dataIdentifier: [
Expand Down Expand Up @@ -642,10 +642,10 @@ describe('log group', () => {
Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogGroup', {
LogGroupName: logGroupName,
DataProtectionPolicy: {
name: 'test-policy-name',
description: 'test description',
version: '2021-06-01',
statement: [
Name: 'test-policy-name',
Description: 'test description',
Version: '2021-06-01',
Statement: [
{
sid: 'audit-statement-cdk',
dataIdentifier: [
Expand Down Expand Up @@ -717,10 +717,10 @@ describe('log group', () => {
Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogGroup', {
LogGroupName: logGroupName,
DataProtectionPolicy: {
name: 'data-protection-policy-cdk',
description: 'cdk generated data protection policy',
version: '2021-06-01',
statement: [
Name: 'data-protection-policy-cdk',
Description: 'cdk generated data protection policy',
Version: '2021-06-01',
Statement: [
{
sid: 'audit-statement-cdk',
dataIdentifier: [
Expand Down Expand Up @@ -801,18 +801,18 @@ describe('log group', () => {
Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogGroup', {
LogGroupName: logGroupName,
DataProtectionPolicy: {
name: 'test-policy-name',
description: 'test description',
version: '2021-06-01',
configuration: {
Name: 'test-policy-name',
Description: 'test description',
Version: '2021-06-01',
Configuration: {
customDataIdentifier: [
{
name: 'EmployeeId',
regex: 'EmployeeId-\\d{9}',
},
],
},
statement: [
Statement: [
{
sid: 'audit-statement-cdk',
dataIdentifier: [
Expand Down Expand Up @@ -861,18 +861,18 @@ describe('log group', () => {
Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogGroup', {
LogGroupName: logGroupName,
DataProtectionPolicy: {
name: 'test-policy-name',
description: 'test description',
version: '2021-06-01',
configuration: {
Name: 'test-policy-name',
Description: 'test description',
Version: '2021-06-01',
Configuration: {
customDataIdentifier: [
{
name: 'EmployeeId',
regex: 'EmployeeId-\\d{9}',
},
],
},
statement: [
Statement: [
{
sid: 'audit-statement-cdk',
dataIdentifier: [
Expand Down
Loading