-
Notifications
You must be signed in to change notification settings - Fork 1
/
primary.tf
72 lines (52 loc) · 1.65 KB
/
primary.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
resource "aws_s3_bucket" "primary" {
provider = aws.primary
bucket = var.primary_name
force_destroy = var.force_destroy
tags = merge(var.default_tags, var.primary_s3_bucket_tags)
}
resource "aws_s3_bucket_versioning" "primary" {
provider = aws.primary
bucket = aws_s3_bucket.primary.bucket
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket_replication_configuration" "primary" {
provider = aws.primary
depends_on = [aws_s3_bucket_versioning.primary]
role = aws_iam_role.replication.arn
bucket = aws_s3_bucket.primary.bucket
rule {
id = aws_s3_bucket.secondary.bucket
filter {} # rule requires no filter but attr must be specified
status = "Enabled"
delete_marker_replication {
status = "Enabled"
}
destination {
bucket = aws_s3_bucket.secondary.arn
}
}
}
data "aws_iam_policy_document" "primary" {
provider = aws.primary
statement {
actions = [
"s3:GetReplicationConfiguration",
"s3:ListBucket",
]
# Don't use Terraform reference to bucket's ARN here as this would produce a circular dependency:
# bucket depends on role depends on policy depends on this data source depends on bucket's ARN
resources = ["arn:aws:s3:::${var.primary_name}"]
}
statement {
actions = [
"s3:GetObjectVersion",
"s3:GetObjectVersionAcl",
"s3:GetObjectVersionTagging",
]
# Don't use Terraform reference to bucket's ARN here as this would produce a circular dependency:
# bucket depends on role depends on policy depends on this data source depends on bucket's ARN
resources = ["arn:aws:s3:::${var.primary_name}/*"]
}
}