forked from SPHTech-Platform/terraform-aws-codebuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
65 lines (52 loc) · 1.61 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
module "codebuild_service_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role"
version = "~> 5.2.0"
create_role = var.create_service_role
trusted_role_services = [
"codebuild.amazonaws.com",
]
role_name = coalesce(var.service_role_name, "${var.name}-codebuild-${var.env}")
role_requires_mfa = false
custom_role_policy_arns = concat([
module.codebuild_service_role_policy.arn,
], var.additional_policy_arns)
}
module "codebuild_service_role_policy" {
source = "terraform-aws-modules/iam/aws//modules/iam-policy"
version = "~> 5.2.0"
create_policy = var.create_service_role
name = "${var.name}-codebuild-${var.env}"
path = "/"
description = "${var.name} IAM Policy"
policy = data.aws_iam_policy_document.codebuild_inline_policy.json
}
data "aws_iam_policy_document" "codebuild_inline_policy" {
source_policy_documents = concat([
data.aws_iam_policy_document.codebuild.json,
], var.additional_iam)
}
data "aws_iam_policy_document" "codebuild" {
statement {
resources = [
"arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:/aws/codebuild/${var.name}:log-stream:*",
]
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
]
}
dynamic "statement" {
for_each = var.artifacts_bucket_name != "" ? [1] : []
content {
resources = [
"arn:aws:s3:::${var.artifacts_bucket_name}/*",
]
actions = [
"s3:GetObject",
"s3:GetObjectVersion",
"s3:PutObject",
]
}
}
}