-
Notifications
You must be signed in to change notification settings - Fork 0
/
bucket_originals.tf
173 lines (141 loc) · 4.44 KB
/
bucket_originals.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
#
# Original assets, as ingested, in a private bucket
#
# Replication rule only for production.
#
resource "aws_s3_bucket" "originals" {
bucket = "${local.name_prefix}-originals"
lifecycle {
prevent_destroy = true
}
tags = {
"service" = local.service_tag
"use" = "originals"
"S3-Bucket-Name" = "${local.name_prefix}-originals"
}
}
resource "aws_s3_bucket_replication_configuration" "originals" {
count = terraform.workspace == "production" ? 1 : 0
bucket = aws_s3_bucket.originals.id
role = aws_iam_role.replication[0].arn
rule {
id = "Backup"
priority = 0
status = "Enabled"
destination {
bucket = aws_s3_bucket.originals_backup[0].arn
}
}
}
# Cloudfront distro fronting originals is RESTRICTED and needs signed urls,
#
# And it passes on response-content-disposition and response-content-type
#
resource "aws_cloudfront_distribution" "originals" {
comment = "${terraform.workspace}-originals S3"
enabled = true
is_ipv6_enabled = true
http_version = "http2and3"
# Only North America/Europe to save money
price_class = "PriceClass_100"
default_cache_behavior {
allowed_methods = [
"GET",
"HEAD",
"OPTIONS",
]
cached_methods = [
"GET",
"HEAD",
"OPTIONS",
]
compress = true
target_origin_id = aws_s3_bucket.originals.bucket_regional_domain_name
viewer_protocol_policy = "https-only"
trusted_key_groups = [aws_cloudfront_key_group.scihist-digicoll.id]
cache_policy_id = aws_cloudfront_cache_policy.caching-optimized-plus-s3-params.id
# Don't need CORS on originals at present, but I guess security is good?
response_headers_policy_id = data.aws_cloudfront_response_headers_policy.Managed-SecurityHeadersPolicy.id
}
origin {
connection_attempts = 3
connection_timeout = 1
domain_name = aws_s3_bucket.originals.bucket_regional_domain_name
origin_id = aws_s3_bucket.originals.bucket_regional_domain_name
origin_access_control_id = aws_cloudfront_origin_access_control.signing-s3.id
}
restrictions {
geo_restriction {
locations = []
restriction_type = "none"
}
}
viewer_certificate {
cloudfront_default_certificate = true
}
tags = {
"service" = local.service_tag
"use" = "originals"
"S3-Bucket-Name" = "${local.name_prefix}-originals"
"Cloudfront-Distribution-Origin-Id" = "${terraform.workspace}-originals.s3"
}
logging_config {
bucket = aws_s3_bucket.chf-logs.bucket_domain_name
include_cookies = false
prefix = "cloudfront_access_logs/${terraform.workspace}-originals"
}
}
resource "aws_s3_bucket_policy" "originals" {
bucket = aws_s3_bucket.originals.id
policy = templatefile("templates/s3_cloudfront_access_policy.tftpl",
{
bucket_name : aws_s3_bucket.originals.id,
cloudfront_arn : aws_cloudfront_distribution.originals.arn
})
}
resource "aws_s3_bucket_public_access_block" "originals" {
bucket = aws_s3_bucket.originals.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
resource "aws_s3_bucket_lifecycle_configuration" "originals" {
bucket = aws_s3_bucket.originals.id
rule {
status = "Enabled"
id = "Expire previous files"
noncurrent_version_expiration {
noncurrent_days = 30
}
}
rule {
status = "Enabled"
id = "scihist-digicoll-${terraform.workspace}-originals-IT-Rule"
transition {
days = 30
storage_class = "INTELLIGENT_TIERING"
}
}
}
resource "aws_s3_bucket_versioning" "originals" {
bucket = aws_s3_bucket.originals.id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket_server_side_encryption_configuration" "originals" {
bucket = aws_s3_bucket.originals.id
rule {
bucket_key_enabled = false
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
# $ terraform import aws_s3_bucket_logging.originals_logging scihist-digicoll-staging-originals
resource "aws_s3_bucket_logging" "originals_logging" {
bucket = aws_s3_bucket.originals.id
target_bucket = aws_s3_bucket.chf-logs.id
target_prefix = "s3_access_logs/${terraform.workspace}-originals/"
}