Skip to content

Commit

Permalink
fix(logs): ResourcePolicy does not have a defaultChild (#21039)
Browse files Browse the repository at this point in the history
The L1 construct has the wrong name (should have been `Resource`
but was made to be `ResourcePolicy`).

Explicitly assign the default child.


----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr committed Jul 7, 2022
1 parent f2acf41 commit 4076153
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-logs/lib/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class ResourcePolicy extends Resource {
physicalName: props?.resourcePolicyName,
});

new CfnResourcePolicy(this, 'ResourcePolicy', {
const l1 = new CfnResourcePolicy(this, 'ResourcePolicy', {
policyName: Lazy.string({
produce: () => props?.resourcePolicyName ?? Names.uniqueId(this),
}),
Expand All @@ -55,6 +55,8 @@ export class ResourcePolicy extends Resource {
}),
});

this.node.defaultChild = l1;

if (props?.policyStatements) {
this.document.addStatements(...props.policyStatements);
}
Expand Down
11 changes: 11 additions & 0 deletions packages/@aws-cdk/aws-logs/test/policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,15 @@ describe('resource policy', () => {
PolicyName: 'ResourcePolicy',
});
});

test('ResourcePolicy has a defaultChild', () => {
// GIVEN
const stack = new Stack();

// WHEN
const resourcePolicy = new ResourcePolicy(stack, 'ResourcePolicy');

// THEN
expect(resourcePolicy.node.defaultChild).toBeDefined();
});
});

0 comments on commit 4076153

Please sign in to comment.