-
Notifications
You must be signed in to change notification settings - Fork 11
/
s3.tf
100 lines (78 loc) · 2.36 KB
/
s3.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
resource "aws_s3_bucket" "geff_bucket" {
bucket = local.s3_bucket_name
}
resource "aws_s3_bucket_ownership_controls" "geff_bucket_ownership_controls" {
bucket = aws_s3_bucket.geff_bucket.id
rule {
object_ownership = var.bucket_object_ownership_settings
}
}
resource "aws_s3_bucket_acl" "geff_bucket_acl" {
count = var.bucket_object_ownership_settings == "BucketOwnerPreferred" ? 1 : 0
bucket = aws_s3_bucket.geff_bucket.id
acl = "private"
depends_on = [aws_s3_bucket_ownership_controls.geff_bucket_ownership_controls]
}
resource "aws_s3_object" "geff_meta_folder" {
bucket = aws_s3_bucket.geff_bucket.id
key = "meta/"
}
resource "random_string" "random" {
length = 5
special = false
}
resource "aws_sns_topic" "geff_bucket_sns" {
name = "${local.s3_sns_topic_name}-${random_string.random.result}"
}
data "aws_iam_policy_document" "geff_s3_sns_topic_policy_doc" {
policy_id = local.s3_sns_policy_name
statement {
sid = "SNSPublish"
effect = "Allow"
resources = [aws_sns_topic.geff_bucket_sns.arn]
actions = ["SNS:Publish"]
principals {
type = "AWS"
identifiers = ["*"]
}
condition {
test = "ArnLike"
variable = "aws:SourceArn"
values = concat(
[aws_s3_bucket.geff_bucket.arn],
var.data_bucket_arns
)
}
}
statement {
sid = "SNSSubscribe"
effect = "Allow"
resources = [aws_sns_topic.geff_bucket_sns.arn]
actions = ["sns:Subscribe"]
principals {
type = "AWS"
identifiers = [local.storage_integration_user_arn]
}
}
}
resource "aws_sns_topic_policy" "geff_s3_sns_topic_policy" {
arn = aws_sns_topic.geff_bucket_sns.arn
policy = data.aws_iam_policy_document.geff_s3_sns_topic_policy_doc.json
}
resource "aws_s3_bucket_notification" "geff_s3_bucket_notification" {
bucket = aws_s3_bucket.geff_bucket.id
topic {
topic_arn = aws_sns_topic.geff_bucket_sns.arn
events = ["s3:ObjectCreated:*"]
}
depends_on = [aws_sns_topic_policy.geff_s3_sns_topic_policy]
}
resource "aws_s3_bucket_notification" "geff_s3_pipline_bucket_notification" {
for_each = toset(local.pipeline_bucket_ids)
bucket = each.key
topic {
topic_arn = aws_sns_topic.geff_bucket_sns.arn
events = ["s3:ObjectCreated:*"]
}
depends_on = [aws_sns_topic_policy.geff_s3_sns_topic_policy]
}