forked from ExpediaGroup/apiary-data-lake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3-other.tf
162 lines (137 loc) · 4.35 KB
/
s3-other.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
* Copyright (C) 2018-2020 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
resource "aws_s3_bucket" "apiary_inventory_bucket" {
count = var.s3_enable_inventory == true ? 1 : 0
bucket = local.s3_inventory_bucket
acl = "private"
tags = merge(map("Name", "${local.s3_inventory_bucket}"), "${var.apiary_tags}")
policy = <<EOF
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"InventoryAndAnalyticsPolicy",
"Effect":"Allow",
"Principal": {"Service": "s3.amazonaws.com"},
"Action":["s3:PutObject"],
"Resource":["arn:aws:s3:::${local.s3_inventory_bucket}/*"],
"Condition": {
"ArnLike": {
"aws:SourceArn": "arn:aws:s3:::${local.apiary_bucket_prefix}-*"
},
"StringEquals": {
"aws:SourceAccount": "${data.aws_caller_identity.current.account_id}",
"s3:x-amz-acl": "bucket-owner-full-control"
}
}
}
]
}
EOF
lifecycle_rule {
enabled = true
abort_incomplete_multipart_upload_days = var.s3_lifecycle_abort_incomplete_multipart_upload_days
}
}
resource "aws_s3_bucket_public_access_block" "apiary_inventory_bucket" {
count = var.s3_enable_inventory == true ? 1 : 0
bucket = aws_s3_bucket.apiary_inventory_bucket[0].bucket
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
}
resource "aws_s3_bucket_ownership_controls" "apiary_inventory_bucket" {
count = var.s3_enable_inventory == true ? 1 : 0
bucket = aws_s3_bucket.apiary_inventory_bucket[0].bucket
rule {
object_ownership = "BucketOwnerPreferred"
}
}
resource "aws_s3_bucket" "apiary_managed_logs_bucket" {
count = local.enable_apiary_s3_log_management ? 1 : 0
bucket = local.apiary_s3_logs_bucket
acl = "log-delivery-write"
tags = merge(map("Name", local.apiary_s3_logs_bucket), var.apiary_tags)
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
lifecycle_rule {
enabled = true
abort_incomplete_multipart_upload_days = var.s3_lifecycle_abort_incomplete_multipart_upload_days
transition {
days = 30
storage_class = "INTELLIGENT_TIERING"
}
expiration {
days = var.s3_log_expiry
}
}
}
resource "aws_s3_bucket_public_access_block" "apiary_managed_logs_bucket" {
count = local.enable_apiary_s3_log_management ? 1 : 0
bucket = aws_s3_bucket.apiary_managed_logs_bucket[0].bucket
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
}
resource "aws_s3_bucket_notification" "apiary_managed_logs_bucket" {
count = local.enable_apiary_s3_log_management ? 1 : 0
bucket = aws_s3_bucket.apiary_managed_logs_bucket[0].bucket
queue {
queue_arn = aws_sqs_queue.apiary_managed_logs_queue[0].arn
events = ["s3:ObjectCreated:*"]
}
}
resource "aws_s3_bucket" "apiary_access_logs_hive" {
count = local.enable_apiary_s3_log_hive ? 1 : 0
bucket = local.apiary_s3_hive_logs_bucket
tags = merge(map("Name", local.apiary_s3_hive_logs_bucket), var.apiary_tags)
acl = "private"
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
lifecycle_rule {
enabled = true
abort_incomplete_multipart_upload_days = var.s3_lifecycle_abort_incomplete_multipart_upload_days
}
}
resource "aws_s3_bucket_public_access_block" "apiary_access_logs_hive" {
count = local.enable_apiary_s3_log_hive ? 1 : 0
bucket = aws_s3_bucket.apiary_access_logs_hive[0].bucket
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
}
resource "aws_s3_bucket" "apiary_system" {
bucket = local.apiary_system_bucket
tags = merge(map("Name", local.apiary_system_bucket), var.apiary_tags)
acl = "private"
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
lifecycle_rule {
enabled = true
abort_incomplete_multipart_upload_days = var.s3_lifecycle_abort_incomplete_multipart_upload_days
}
}
resource "aws_s3_bucket_public_access_block" "apiary_system" {
bucket = aws_s3_bucket.apiary_system.bucket
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
}