-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam.tf
115 lines (95 loc) · 2.29 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
resource "aws_iam_role" "replication_role" {
name = "s3-replication-role-${var.bucket_name}"
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "s3.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
POLICY
}
########## POLICY DOCS ############
data "aws_iam_policy_document" "s3_access_policy" {
statement {
effect = "Allow"
actions = [
"s3:ListBucket",
"s3:GetBucketLocation",
"s3:ListBucketMultipartUploads",
]
resources = [
"${aws_s3_bucket.s3-bucket.arn}",
]
}
statement {
effect = "Allow"
actions = [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:ListMultipartUploadParts",
]
resources = [
"${aws_s3_bucket.s3-bucket.arn}/*",
]
}
}
data "aws_iam_policy_document" "replica_access_policy" {
statement {
effect = "Allow"
actions = [
"s3:GetReplicationConfiguration",
"s3:ListBucket",
]
resources = [
"${aws_s3_bucket.s3-bucket.arn}",
]
}
statement {
effect = "Allow"
actions = [
"s3:GetObjectVersion",
"s3:GetObjectVersionAcl",
]
resources = [
"${aws_s3_bucket.s3-bucket.arn}/*",
]
}
statement {
effect = "Allow"
actions = [
"s3:ReplicateObject",
"s3:ReplicateDelete",
]
resources = [
"${aws_s3_bucket.repl-s3-bucket.arn}/*",
]
}
}
resource "aws_iam_policy" "bucket_policy" {
name = "s3-${var.bucket_name}-policy"
policy = "${data.aws_iam_policy_document.s3_access_policy.json}"
}
resource "aws_iam_policy" "replication_policy" {
name = "s3-${var.repl_bucket_name}-policy"
policy = "${data.aws_iam_policy_document.replica_access_policy.json}"
}
resource "aws_iam_policy_attachment" "s3_attach" {
name = "${var.bucket_name}-policy-attachment"
users = ["${var.bucket_access_user_names}"]
roles = ["${var.bucket_access_role_names}"]
policy_arn = "${aws_iam_policy.bucket_policy.arn}"
}
resource "aws_iam_policy_attachment" "replication_attach" {
name = "${var.repl_bucket_name}-policy-attachment"
roles = ["${aws_iam_role.replication_role.name}"]
policy_arn = "${aws_iam_policy.replication_policy.arn}"
}