-
Notifications
You must be signed in to change notification settings - Fork 26
/
iam.tf
85 lines (72 loc) · 2.01 KB
/
iam.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Service role
resource "aws_iam_role" "service_role" {
count = var.create_default_service_role ? 1 : 0
name = "${var.name}-service-role"
assume_role_policy = element(data.aws_iam_policy_document.codebuild_assume_role_policy.*.json, 0)
}
# Add extra polcies
resource "aws_iam_role_policy" "codebuild_role_extra_policies" {
count = var.create_default_service_role ? 1 : 0
role = element(aws_iam_role.service_role.*.name, 0)
policy = element(data.aws_iam_policy_document.codebuild_role_extra_policies.*.json, 0)
}
####################
# Policy documents #
####################
# Assume Role
data "aws_iam_policy_document" "codebuild_assume_role_policy" {
count = var.create_default_service_role ? 1 : 0
statement {
effect = "Allow"
principals {
type = "Service"
identifiers = ["codebuild.amazonaws.com"]
}
actions = [
"sts:AssumeRole",
]
}
}
# Extra policies
data "aws_iam_policy_document" "codebuild_role_extra_policies" {
count = var.create_default_service_role ? 1 : 0
statement {
effect = "Allow"
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
]
resources = [
"arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:/aws/codebuild/${var.name}",
"arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:/aws/codebuild/${var.name}:*",
]
}
statement {
effect = "Allow"
actions = [
"s3:GetObject",
"s3:GetObjectVersion",
"s3:PutObject",
]
resources = [
"arn:aws:s3:::codepipeline-${data.aws_region.current.name}-*",
]
}
statement {
effect = "Allow"
actions = [
"ec2:CreateNetworkInterface",
"ec2:DeleteNetworkInterface",
"ec2:Describe*",
]
resources = ["*"]
}
statement {
effect = "Allow"
actions = [
"ec2:CreateNetworkInterfacePermission"
]
resources = ["*"]
}
}