@cryptotaxi247 / infra / commits / ab93c406

Add Terraform resources for cache.nixos.org

Fixes #47.

Eelco Dolstra committed Jul 19, 2018 at 16:30 UTC ab93c4068c56fbb7da51490d2d134d7572197345
1 file changed +72
terraform/cache.tf new
+72
@@ -0,0 +1,72 @@
1 +resource "aws_cloudfront_distribution" "cache" {
2 + enabled = true
3 + is_ipv6_enabled = true
4 + price_class = "PriceClass_All"
5 + aliases = ["cache.nixos.org"]
6 +
7 + origin {
8 + origin_id = "S3-nix-cache"
9 + domain_name = "nix-cache.s3.amazonaws.com"
10 + s3_origin_config {
11 + origin_access_identity = "origin-access-identity/cloudfront/E11I84008FX6W9"
12 + }
13 + }
14 +
15 + default_cache_behavior {
16 + allowed_methods = ["HEAD", "GET"]
17 + cached_methods = ["HEAD", "GET"]
18 + target_origin_id = "S3-nix-cache"
19 + viewer_protocol_policy = "allow-all"
20 + min_ttl = 0
21 + default_ttl = 86400
22 + max_ttl = 31536000
23 +
24 + forwarded_values {
25 + query_string = false
26 +
27 + cookies {
28 + forward = "none"
29 + }
30 + }
31 + }
32 +
33 + viewer_certificate {
34 + cloudfront_default_certificate = true
35 + acm_certificate_arn = "${aws_acm_certificate.cache.arn}"
36 + ssl_support_method = "sni-only"
37 + }
38 +
39 + restrictions {
40 + geo_restriction {
41 + restriction_type = "none"
42 + }
43 + }
44 +
45 + logging_config {
46 + bucket = "nix-cache-logs.s3.amazonaws.com"
47 + }
48 +
49 + custom_error_response {
50 + error_code = 403
51 + response_page_path = "/error-pages/404"
52 + response_code = 404
53 + error_caching_min_ttl = 600
54 + }
55 +
56 + custom_error_response {
57 + error_code = 500
58 + error_caching_min_ttl = 10
59 + }
60 +
61 + default_root_object = "index.html"
62 +}
63 +
64 +resource "aws_acm_certificate" "cache" {
65 + provider = "aws.us"
66 + domain_name = "cache.nixos.org"
67 + validation_method = "DNS"
68 +
69 + lifecycle {
70 + create_before_destroy = true
71 + }
72 +}