tf/releases: add fastly configuration
zimbatm committed
Aug 30, 2021 at 21:44 UTC
682bd48b03077e374d81fb261f86be42a0e7741f
1 file changed
+86
terraform/releases.tf
+86
@@ -138,3 +138,89 @@ resource "aws_acm_certificate" "releases" {
138
create_before_destroy = true
139
}
140
}
141
+
142
+resource "fastly_service_v1" "releases" {
143
+ name = local.releases_domain
144
+ default_ttl = 86400
145
+
146
+ backend {
147
+ address = "s3.amazonaws.com"
148
+ auto_loadbalance = false
149
+ between_bytes_timeout = 10000
150
+ connect_timeout = 5000
151
+ error_threshold = 0
152
+ first_byte_timeout = 15000
153
+ max_conn = 200
154
+ name = "s3.amazonaws.com"
155
+ override_host = aws_s3_bucket.releases.bucket_domain_name
156
+ port = 443
157
+ shield = "bwi-va-us"
158
+ ssl_cert_hostname = "s3.amazonaws.com"
159
+ ssl_check_cert = true
160
+ use_ssl = true
161
+ weight = 100
162
+ }
163
+
164
+ condition {
165
+ name = "Generated by synthetic response for 404 page"
166
+ priority = 0
167
+ statement = "beresp.status == 404"
168
+ type = "CACHE"
169
+ }
170
+
171
+ condition {
172
+ name = "Match /"
173
+ priority = 10
174
+ statement = "req.url ~ \"^/$\""
175
+ type = "REQUEST"
176
+ }
177
+
178
+ domain {
179
+ name = local.releases_domain
180
+ }
181
+
182
+ header {
183
+ action = "set"
184
+ destination = "url"
185
+ ignore_if_set = false
186
+ name = "Landing page"
187
+ priority = 10
188
+ request_condition = "Match /"
189
+ source = "\"/index.html\""
190
+ type = "request"
191
+ }
192
+
193
+ response_object {
194
+ cache_condition = "Generated by synthetic response for 404 page"
195
+ content = "404"
196
+ content_type = "text/html"
197
+ name = "Generated by synthetic response for 404 page"
198
+ response = "Not Found"
199
+ status = 404
200
+ }
201
+
202
+ snippet {
203
+ content = <<-EOT
204
+ if (beresp.status == 403) {
205
+ set beresp.status = 404;
206
+ set beresp.ttl = 86400s;
207
+ set beresp.grace = 0s;
208
+ set beresp.cacheable = true;
209
+ }
210
+ EOT
211
+ name = "Change 403 from S3 to 404"
212
+ priority = 100
213
+ type = "fetch"
214
+ }
215
+}
216
+
217
+resource "fastly_tls_subscription" "releases" {
218
+ domains = [for domain in fastly_service_v1.releases.domain : domain.name]
219
+ configuration_id = local.fastly_tls12_sni_configuration_id
220
+ certificate_authority = "globalsign"
221
+}
222
+
223
+# TODO: move the DNS config to terraform
224
+output "releases-managed_dns_challenge" {
225
+ value = fastly_tls_subscription.releases.managed_dns_challenge
226
+}