cloudcomponents / cdk-constructs

A collection of higher-level reusable cdk constructs
MIT License
623 stars 101 forks source link

Ability to use the Pull Request Check Function/Role as part of Approval Pool Members. #135

Closed mbp closed 2 years ago

mbp commented 2 years ago

When combining pull-request-check and pull-request-approval-rule packages, it is not currently possible to require that the approval is made by the actual Pull Request Check. We need to populate the approvalPoolMembers property. In my experience, I found when Pull Request Check approves a Pull Request, it does so by with the IAM role syntax {roleArn}/{lambdaArn}.

So concretely one would put this

template: {
   approvers: {
      numberOfApprovalsNeeded: 1,
      approvalPoolMembers: ["CodeBuildResultFunct-8RGRK7JL2MC7/CodeBuildResultFunct-G61QZIY7XP0F"],
   },
},

If list of approval pool members is empty, then any type of approval, will satisfy the approval rule, which might not be desired.

Hardcoding the resource names in approvalPoolMembers are obviously not good, so therefor I changed PullRequestCheck to expose the underlying Lambda function. After this change, one can do:

template: {
   approvers: {
      numberOfApprovalsNeeded: 1,
      approvalPoolMembers: ['CodeCommitApprovers:' + prCheck.codeBuildResultFunction?.role?.roleName + '/' + prCheck.codeBuildResultFunction?.functionName]
   },
},