-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiam-source.tf
94 lines (90 loc) · 2 KB
/
iam-source.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
resource "aws_iam_role" "replication" {
provider = aws.source
name = var.replication_role_name
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "s3.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
POLICY
}
resource "aws_iam_policy" "replication" {
provider = aws.source
name = var.replication_policy_name
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:GetReplicationConfiguration",
"s3:ListBucket"
],
"Effect": "Allow",
"Resource": [
"${aws_s3_bucket.source.arn}"
]
},
{
"Action": [
"s3:GetObjectVersionForReplication",
"s3:GetObjectVersionAcl",
"s3:GetObjectVersionTagging"
],
"Effect": "Allow",
"Resource": [
"${aws_s3_bucket.source.arn}/*"
]
},
{
"Action": [
"s3:ReplicateObject",
"s3:ReplicateDelete",
"s3:ReplicateTags"
],
"Effect": "Allow",
"Resource": "${aws_s3_bucket.destination.arn}/*"
},
{
"Action": ["kms:Decrypt"],
"Effect": "Allow",
"Resource": [
"${aws_kms_key.dest-kms-key.arn}",
"${aws_kms_key.source-kms-key.arn}"
],
"Condition": {
"StringLike": {
"kms:ViaService": "s3.${var.source_region}.amazonaws.com",
"kms:EncryptionContext:aws:s3:arn": "arn:aws:s3:::${var.bucket_source_name}/*"
}
}
},
{
"Action": ["kms:Encrypt"],
"Effect": "Allow",
"Resource": "${aws_kms_key.dest-kms-key.arn}",
"Condition": {
"StringLike": {
"kms:ViaService": "s3.${var.dest_region}.amazonaws.com",
"kms:EncryptionContext:aws:s3:arn": "arn:aws:s3:::${var.bucket_dest_name}/*"
}
}
}
]
}
POLICY
}
resource "aws_iam_role_policy_attachment" "replication" {
provider = aws.source
role = aws_iam_role.replication.name
policy_arn = aws_iam_policy.replication.arn
}