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 a bug where addToResourcePolicy was not working #737

Merged
merged 1 commit into from
Sep 19, 2018
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
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecr/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class Repository extends RepositoryRef {
const resource = new cloudformation.RepositoryResource(this, 'Resource', {
repositoryName: props.repositoryName,
// It says "Text", but they actually mean "Object".
repositoryPolicyText: this.policyDocument,
repositoryPolicyText: new cdk.Token(() => this.policyDocument),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PolicyDocument should be a Token already, so this should not be necessary. Will investigate tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the test I added didn't pass without this change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that. Will check into why tomorrow. Boo on me for not writing this test in the first place ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh duh. It's not an object at construction time yet. It's lazily instantiated when you first call addToResourcePolicy.

lifecyclePolicy: new cdk.Token(() => this.renderLifecyclePolicy()),
});

Expand Down
24 changes: 24 additions & 0 deletions packages/@aws-cdk/aws-ecr/test/test.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,30 @@ export = {
'Fn::ImportValue': 'RepoRepositoryArn7F2901C9'
});

test.done();
},

'resource policy'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const repo = new ecr.Repository(stack, 'Repo');

// WHEN
repo.addToResourcePolicy(new cdk.PolicyStatement().addAction('*'));

// THEN
expect(stack).to(haveResource('AWS::ECR::Repository', {
RepositoryPolicyText: {
Statement: [
{
Action: "*",
Effect: "Allow"
}
],
Version: "2012-10-17"
},
}));

test.done();
}
};