Skip to content

Commit e43cdde

Browse files
authored
Merge pull request #30 from aws-samples/vpc_perms
update codebuild vpc perms
2 parents 268e9e4 + 7c46b39 commit e43cdde

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

codebuild.tf

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,54 @@ data "aws_iam_policy_document" "codebuild" {
148148
]
149149
}
150150

151+
// https://docs.aws.amazon.com/codebuild/latest/userguide/auth-and-access-control-iam-identity-based-access-control.html#customer-managed-policies-example-create-vpc-network-interface
151152
dynamic "statement" {
152153
for_each = var.vpc == null ? [] : [var.vpc]
153154
content {
154155
effect = "Allow"
155156
actions = [
156-
"ec2:DescribeSecurityGroups",
157+
"ec2:CreateNetworkInterface",
158+
"ec2:DescribeDhcpOptions",
159+
"ec2:DescribeNetworkInterfaces",
160+
"ec2:DeleteNetworkInterface",
157161
"ec2:DescribeSubnets",
162+
"ec2:DescribeSecurityGroups",
158163
"ec2:DescribeVpcs"
159164
]
160165
resources = [
161166
"*"
162167
]
163168
}
164169
}
170+
171+
dynamic "statement" {
172+
for_each = var.vpc == null ? [] : [var.vpc]
173+
content {
174+
effect = "Allow"
175+
actions = [
176+
"ec2:CreateNetworkInterfacePermission"
177+
178+
]
179+
resources = [
180+
"arn:aws:ec2:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:network-interface/*"
181+
]
182+
condition {
183+
test = "StringEquals"
184+
variable = "ec2:AuthorizedService"
185+
values = [
186+
"codebuild.amazonaws.com"
187+
]
188+
}
189+
condition {
190+
test = "ArnEquals"
191+
variable = "ec2:Subnet"
192+
values = [
193+
for id in var.vpc["subnets"] :
194+
"arn:aws:ec2:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:subnet/${id}"
195+
]
196+
}
197+
}
198+
}
165199
}
166200

167201
resource "aws_codebuild_report_group" "sast" {

0 commit comments

Comments
 (0)