forked from cloudposse/terraform-aws-tfstate-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
replication.tf
66 lines (55 loc) · 1.65 KB
/
replication.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
resource "aws_iam_role" "replication" {
count = local.enabled && var.s3_replication_enabled ? 1 : 0
name = format("%s-replication", module.this.id)
assume_role_policy = data.aws_iam_policy_document.replication_sts[0].json
}
data "aws_iam_policy_document" "replication_sts" {
count = local.enabled && var.s3_replication_enabled ? 1 : 0
statement {
sid = "AllowPrimaryToAssumeServiceRole"
effect = "Allow"
actions = [
"sts:AssumeRole"
]
principals {
type = "Service"
identifiers = ["s3.amazonaws.com"]
}
}
}
resource "aws_iam_policy" "replication" {
count = local.enabled && var.s3_replication_enabled ? 1 : 0
name = format("%s-replication", module.this.id)
policy = data.aws_iam_policy_document.replication[0].json
}
data "aws_iam_policy_document" "replication" {
count = local.enabled && var.s3_replication_enabled ? 1 : 0
statement {
sid = "AllowPrimaryToGetReplicationConfiguration"
effect = "Allow"
actions = [
"s3:Get*",
"s3:ListBucket"
]
resources = [
join("", aws_s3_bucket.default.*.arn),
"${join("", aws_s3_bucket.default.*.arn)}/*"
]
}
statement {
sid = "AllowPrimaryToReplicate"
effect = "Allow"
actions = [
"s3:ReplicateObject",
"s3:ReplicateDelete",
"s3:ReplicateTags",
"s3:GetObjectVersionTagging"
]
resources = ["${var.s3_replica_bucket_arn}/*"]
}
}
resource "aws_iam_role_policy_attachment" "replication" {
count = local.enabled && var.s3_replication_enabled ? 1 : 0
role = aws_iam_role.replication[0].name
policy_arn = aws_iam_policy.replication[0].arn
}