-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3-source.tf
126 lines (106 loc) · 3.82 KB
/
s3-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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# S3 source IAM and bucket
# S3 source IAM
data "aws_iam_policy_document" "source_replication_role" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["s3.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "source_replication_policy" {
statement {
actions = [
"s3:GetReplicationConfiguration",
"s3:ListBucket",
]
# TF-UPGRADE-TODO: In Terraform v0.10 and earlier, it was sometimes necessary to
# force an interpolation expression to be interpreted as a list by wrapping it
# in an extra set of list brackets. That form was supported for compatibility in
# v0.11, but is no longer supported in Terraform v0.12.
#
# If the expression in the following list itself returns a list, remove the
# brackets to avoid interpretation as a list of lists. If the expression
# returns a single list item then leave it as-is and remove this TODO comment.
resources = [
local.source_bucket_arn,
]
}
statement {
actions = [
"s3:GetObjectVersionForReplication",
"s3:GetObjectVersionAcl",
]
# TF-UPGRADE-TODO: In Terraform v0.10 and earlier, it was sometimes necessary to
# force an interpolation expression to be interpreted as a list by wrapping it
# in an extra set of list brackets. That form was supported for compatibility in
# v0.11, but is no longer supported in Terraform v0.12.
#
# If the expression in the following list itself returns a list, remove the
# brackets to avoid interpretation as a list of lists. If the expression
# returns a single list item then leave it as-is and remove this TODO comment.
resources = [
local.source_bucket_object_arn,
]
}
statement {
actions = [
"s3:ReplicateObject",
"s3:ReplicateDelete",
"s3:ObjectOwnerOverrideToBucketOwner",
]
# TF-UPGRADE-TODO: In Terraform v0.10 and earlier, it was sometimes necessary to
# force an interpolation expression to be interpreted as a list by wrapping it
# in an extra set of list brackets. That form was supported for compatibility in
# v0.11, but is no longer supported in Terraform v0.12.
#
# If the expression in the following list itself returns a list, remove the
# brackets to avoid interpretation as a list of lists. If the expression
# returns a single list item then leave it as-is and remove this TODO comment.
resources = [
local.dest_bucket_object_arn,
]
}
}
resource "aws_iam_role" "source_replication" {
provider = aws.source_of_replication
name = "${local.replication_name}-replication-role"
assume_role_policy = data.aws_iam_policy_document.source_replication_role.json
}
resource "aws_iam_policy" "source_replication" {
provider = aws.source_of_replication
name = "${local.replication_name}-replication-policy"
policy = data.aws_iam_policy_document.source_replication_policy.json
}
resource "aws_iam_role_policy_attachment" "source_replication" {
provider = aws.source_of_replication
role = aws_iam_role.source_replication.name
policy_arn = aws_iam_policy.source_replication.arn
}
# S3 source bucket
resource "aws_s3_bucket" "source" {
provider = aws.source_of_replication
bucket = var.source_bucket_name
region = var.source_region
versioning {
enabled = true
}
replication_configuration {
role = aws_iam_role.source_replication.arn
rules {
id = local.replication_name
status = "Enabled"
priority = var.priority
prefix = var.replicate_prefix
destination {
bucket = local.dest_bucket_arn
storage_class = "STANDARD"
access_control_translation {
owner = "Destination"
}
account_id = data.aws_caller_identity.dest.account_id
}
}
}
}