forked from GSI-Xapiens-CSIRO/sBeacon-BGSi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3.tf
214 lines (176 loc) · 4.72 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#
# S3 bucket for persisted vcf summaries and variant queries
#
resource "aws_s3_bucket" "variants-bucket" {
bucket_prefix = var.variants-bucket-prefix
force_destroy = true
tags = var.common-tags
}
resource "aws_s3_bucket_ownership_controls" "variants_bucket_ownership_controls" {
bucket = aws_s3_bucket.variants-bucket.id
rule {
object_ownership = "BucketOwnerPreferred"
}
}
resource "aws_s3_bucket_acl" "variants_bucket_acl" {
depends_on = [aws_s3_bucket_ownership_controls.variants_bucket_ownership_controls]
bucket = aws_s3_bucket.variants-bucket.id
acl = "private"
}
resource "aws_s3_bucket_lifecycle_configuration" "variants_bucket_lifecycle" {
bucket = aws_s3_bucket.variants-bucket.id
rule {
id = "clean-old-queries"
status = "Enabled"
filter {
prefix = "variant-queries/"
}
expiration {
days = 1
}
}
}
#
# S3 bucket for metadata handling
#
resource "aws_s3_bucket" "metadata-bucket" {
bucket_prefix = var.metadata-bucket-prefix
force_destroy = true
tags = var.common-tags
}
resource "aws_s3_bucket_ownership_controls" "metadata_bucket_ownership_controls" {
bucket = aws_s3_bucket.metadata-bucket.id
rule {
object_ownership = "BucketOwnerPreferred"
}
}
resource "aws_s3_bucket_acl" "metadata" {
depends_on = [aws_s3_bucket_ownership_controls.metadata_bucket_ownership_controls]
bucket = aws_s3_bucket.metadata-bucket.id
acl = "private"
}
resource "aws_s3_bucket_lifecycle_configuration" "metadata_bucket_lifecycle" {
bucket = aws_s3_bucket.metadata-bucket.id
rule {
id = "clean-old-query-results"
status = "Enabled"
filter {
prefix = "query-results/"
}
expiration {
days = 2
}
}
rule {
id = "clean-old-cached-results"
status = "Enabled"
filter {
prefix = "query-responses/"
}
expiration {
days = 2
}
}
}
#
# enable cors for metadata bucket
#
resource "aws_s3_bucket_cors_configuration" "metadata-bucket" {
bucket = aws_s3_bucket.metadata-bucket.id
cors_rule {
allowed_headers = ["*"]
allowed_methods = ["GET", "HEAD"]
allowed_origins = ["*"]
expose_headers = []
max_age_seconds = 3000
}
}
#
# S3 bucket for lambda layers
#
resource "aws_s3_bucket" "lambda-layers-bucket" {
bucket_prefix = var.lambda-layers-bucket-prefix
force_destroy = true
tags = var.common-tags
}
resource "aws_s3_bucket_ownership_controls" "lambda_layers_bucket_ownership_controls" {
bucket = aws_s3_bucket.lambda-layers-bucket.id
rule {
object_ownership = "BucketOwnerPreferred"
}
}
resource "aws_s3_bucket_acl" "lambda-layers" {
depends_on = [aws_s3_bucket_ownership_controls.lambda_layers_bucket_ownership_controls]
bucket = aws_s3_bucket.lambda-layers-bucket.id
acl = "private"
}
#
# S3 bucket for data portal content
#
resource "aws_s3_bucket" "dataportal-bucket" {
bucket_prefix = var.dataportal-bucket-prefix
force_destroy = true
tags = var.common-tags
}
resource "aws_s3_bucket_ownership_controls" "dataportal_bucket_ownership_controls" {
bucket = aws_s3_bucket.dataportal-bucket.id
rule {
object_ownership = "BucketOwnerPreferred"
}
}
resource "aws_s3_bucket_acl" "dataportal_bucket_acl" {
depends_on = [aws_s3_bucket_ownership_controls.dataportal_bucket_ownership_controls]
bucket = aws_s3_bucket.dataportal-bucket.id
acl = "private"
}
resource "aws_s3_bucket_lifecycle_configuration" "staging_bucket_lifecycle" {
bucket = aws_s3_bucket.dataportal-bucket.id
rule {
id = "remove-zombie-staging-files"
status = "Enabled"
filter {
prefix = "staging/"
}
expiration {
days = 3
}
}
}
#
# enable cors for dataportal bucket
#
resource "aws_s3_bucket_cors_configuration" "dataportal-bucket" {
bucket = aws_s3_bucket.dataportal-bucket.id
cors_rule {
allowed_headers = ["*"]
allowed_methods = ["GET", "HEAD", "PUT", "POST", "DELETE"]
allowed_origins = ["*"]
expose_headers = ["ETag", "x-amz-multipart-parts-count", "x-amz-abort-date"]
max_age_seconds = 36000
}
}
#
# Enables S3 bucket notifications for updating file information
#
resource "aws_s3_bucket_notification" "updateFiles" {
bucket = aws_s3_bucket.dataportal-bucket.id
lambda_function {
lambda_function_arn = module.lambda-updateFiles.lambda_function_arn
events = [
"s3:ObjectCreated:*",
"s3:ObjectRemoved:*",
]
filter_prefix = "projects/"
}
lambda_function {
lambda_function_arn = module.lambda-deidentifyFiles.lambda_function_arn
events = [
"s3:ObjectCreated:*",
]
filter_prefix = "staging/projects/"
}
depends_on = [
aws_lambda_permission.S3updateFiles,
aws_lambda_permission.S3deidentifyFiles,
]
}