forked from claranet/terraform-aws-s3-yum-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
78 lines (63 loc) · 1.7 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
# Create the IAM role.
resource "aws_iam_role" "codebuild" {
name = "${var.codebuild_name}"
assume_role_policy = "${data.aws_iam_policy_document.assume_role.json}"
}
data "aws_iam_policy_document" "assume_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["codebuild.amazonaws.com"]
}
}
}
# Create the IAM policy.
resource "aws_iam_policy" "codebuild" {
name = "${var.codebuild_name}"
path = "/service-role/"
description = "Policy used in trust relationship with CodeBuild"
policy = "${data.aws_iam_policy_document.codebuild.json}"
}
data "aws_iam_policy_document" "codebuild" {
statement {
effect = "Allow"
resources = ["*"]
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
]
}
statement {
effect = "Allow"
actions = [
"s3:GetObject",
"s3:GetObjectVersion",
"s3:GetBucketVersioning",
]
resources = [
"arn:aws:s3:::${aws_s3_bucket_object.source.bucket}",
"arn:aws:s3:::${aws_s3_bucket_object.source.bucket}/${aws_s3_bucket_object.source.key}",
]
}
statement {
effect = "Allow"
actions = [
"s3:ListBucket",
"s3:GetObject",
"s3:PutObject",
]
resources = [
"arn:aws:s3:::${var.repo_bucket}",
"arn:aws:s3:::${var.repo_bucket}/${var.repo_dir == "" ? "" : "${var.repo_dir}/"}*",
]
}
}
# Attach the policy to the role.
resource "aws_iam_policy_attachment" "codebuild" {
name = "${var.codebuild_name}"
policy_arn = "${aws_iam_policy.codebuild.arn}"
roles = ["${aws_iam_role.codebuild.id}"]
}