-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
61 lines (57 loc) · 1.7 KB
/
main.tf
File metadata and controls
61 lines (57 loc) · 1.7 KB
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
resource "aws_s3_bucket_versioning" "bucket" {
count = local.is_replicated ? 1 : 0
bucket = aws_s3_bucket.bucket.id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket_acl" "bucket" {
bucket = aws_s3_bucket.bucket.id
acl = "private"
}
resource "aws_s3_bucket_ownership_controls" "bucket" {
bucket = aws_s3_bucket.bucket.id
rule {
object_ownership = "BucketOwnerPreferred"
}
}
resource "aws_s3_bucket_replication_configuration" "replication" {
count = local.is_replicated ? 1 : 0
depends_on = [aws_s3_bucket_versioning.bucket[0]]
role = aws_iam_role.replication[0].arn
bucket = aws_s3_bucket.bucket.id
dynamic "rule" {
for_each = var.replications
content {
id = "all-to-target-${rule.key}"
priority = rule.key
status = "Enabled"
delete_marker_replication {
status = "Enabled"
}
destination {
bucket = rule.value
storage_class = "STANDARD"
}
filter {}
}
}
}
resource "aws_s3_bucket" "bucket" {
bucket = var.bucket_name
}
resource "aws_iam_role" "replication" {
count = local.is_replicated ? 1 : 0
name_prefix = "tf-iam-role-replication-"
assume_role_policy = data.aws_iam_policy_document.s3_replication_assume_role_policy[0].json
}
resource "aws_iam_policy" "replication" {
count = local.is_replicated ? 1 : 0
name_prefix = "tf-iam-role-policy-replication-"
policy = data.aws_iam_policy_document.s3_replication_policy[0].json
}
resource "aws_iam_role_policy_attachment" "replication" {
count = local.is_replicated ? 1 : 0
role = aws_iam_role.replication[0].name
policy_arn = aws_iam_policy.replication[0].arn
}