-
Notifications
You must be signed in to change notification settings - Fork 24
/
s3-source.tf
101 lines (81 loc) · 2.17 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
# 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",
]
resources = [
"${local.source_bucket_arn}",
]
}
statement {
actions = [
"s3:GetObjectVersionForReplication",
"s3:GetObjectVersionAcl",
]
resources = [
"${local.source_bucket_object_arn}",
]
}
statement {
actions = [
"s3:ReplicateObject",
"s3:ReplicateDelete",
"s3:ObjectOwnerOverrideToBucketOwner",
]
resources = [
"${local.dest_bucket_object_arn}",
]
}
}
resource "aws_iam_role" "source_replication" {
provider = "aws.source"
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"
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"
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"
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"
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}"
}
}
}
}