Skip to content

Commit 145da28

Browse files
authored
fix(codebuild): correctly pass the VPC subnet IDs to the Policy Statement's condition when using a VPC. (#2506)
Fixes #2335
1 parent eb13741 commit 145da28

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

packages/@aws-cdk/aws-codebuild/lib/project.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -903,9 +903,9 @@ export class Project extends ProjectBase {
903903
this.addToRolePolicy(new iam.PolicyStatement()
904904
.addResource(`arn:aws:ec2:${Aws.region}:${Aws.accountId}:network-interface/*`)
905905
.addCondition('StringEquals', {
906-
"ec2:Subnet": [
907-
`arn:aws:ec2:${Aws.region}:${Aws.accountId}:subnet/[[subnets]]`
908-
],
906+
"ec2:Subnet": props.vpc
907+
.selectSubnets(props.subnetSelection).subnetIds
908+
.map(si => `arn:aws:ec2:${Aws.region}:${Aws.accountId}:subnet/${si}`),
909909
"ec2:AuthorizedService": "codebuild.amazonaws.com"
910910
})
911911
.addAction('ec2:CreateNetworkInterfacePermission'));

packages/@aws-cdk/aws-codebuild/test/integ.project-vpc.expected.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,10 @@
312312
{
313313
"Ref": "AWS::AccountId"
314314
},
315-
":subnet/[[subnets]]"
315+
":subnet/",
316+
{
317+
"Ref": "MyVPCPrivateSubnet1Subnet641543F4"
318+
}
316319
]
317320
]
318321
}

0 commit comments

Comments
 (0)