|
| 1 | +resource "aws_cloudfront_distribution" "main_website_distribution" { |
| 2 | + enabled = true |
| 3 | + is_ipv6_enabled = true |
| 4 | + comment = "CloudFront distribution for ${var.website_origin_domain_name}" |
| 5 | + default_root_object = "index.html" |
| 6 | + |
| 7 | + origin { |
| 8 | + domain_name = var.website_origin_domain_name |
| 9 | + origin_id = "your-website" |
| 10 | + |
| 11 | + custom_origin_config { |
| 12 | + http_port = 80 |
| 13 | + https_port = 443 |
| 14 | + origin_protocol_policy = "https-only" |
| 15 | + origin_ssl_protocols = ["TLSv1.2"] |
| 16 | + } |
| 17 | + } |
| 18 | + |
| 19 | + default_cache_behavior { |
| 20 | + allowed_methods = ["GET", "HEAD"] |
| 21 | + cached_methods = ["GET", "HEAD"] |
| 22 | + target_origin_id = "your-website" |
| 23 | + |
| 24 | + forwarded_values { |
| 25 | + query_string = false |
| 26 | + cookies { |
| 27 | + forward = "none" |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + viewer_protocol_policy = "redirect-to-https" |
| 32 | + min_ttl = 0 |
| 33 | + default_ttl = 3600 |
| 34 | + max_ttl = 86400 |
| 35 | + } |
| 36 | + |
| 37 | + restrictions { |
| 38 | + geo_restriction { |
| 39 | + restriction_type = "none" |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + aliases = [var.website_domain] |
| 44 | + |
| 45 | + viewer_certificate { |
| 46 | + acm_certificate_arn = var.certificate_arn |
| 47 | + ssl_support_method = "sni-only" |
| 48 | + } |
| 49 | + |
| 50 | + #region Fingerprint CloudFront Integration start |
| 51 | + origin { |
| 52 | + domain_name = module.fingerprint_cloudfront_integration.fpjs_origin_name |
| 53 | + origin_id = module.fingerprint_cloudfront_integration.fpjs_origin_id |
| 54 | + custom_origin_config { |
| 55 | + origin_protocol_policy = "https-only" |
| 56 | + http_port = 80 |
| 57 | + https_port = 443 |
| 58 | + origin_ssl_protocols = ["TLSv1.2"] |
| 59 | + } |
| 60 | + custom_header { |
| 61 | + name = "FPJS_SECRET_NAME" |
| 62 | + value = module.fingerprint_cloudfront_integration.fpjs_secret_manager_arn |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + ordered_cache_behavior { |
| 67 | + path_pattern = "${var.fpjs_behavior_path}/*" |
| 68 | + |
| 69 | + allowed_methods = ["GET", "HEAD", "OPTIONS", "PUT", "POST", "PATCH", "DELETE"] |
| 70 | + cached_methods = ["GET", "HEAD"] |
| 71 | + cache_policy_id = module.fingerprint_cloudfront_integration.fpjs_cache_policy_id |
| 72 | + origin_request_policy_id = module.fingerprint_cloudfront_integration.fpjs_origin_request_policy_id |
| 73 | + target_origin_id = module.fingerprint_cloudfront_integration.fpjs_origin_id |
| 74 | + viewer_protocol_policy = "https-only" |
| 75 | + compress = true |
| 76 | + |
| 77 | + lambda_function_association { |
| 78 | + event_type = "origin-request" |
| 79 | + lambda_arn = module.fingerprint_cloudfront_integration.fpjs_proxy_lambda_arn |
| 80 | + include_body = true |
| 81 | + } |
| 82 | + } |
| 83 | + #endregion |
| 84 | +} |
| 85 | + |
| 86 | + |
| 87 | +resource "aws_route53_record" "apex_domain" { |
| 88 | + zone_id = var.domain_zone_id |
| 89 | + name = var.website_domain |
| 90 | + type = "A" |
| 91 | + |
| 92 | + alias { |
| 93 | + name = aws_cloudfront_distribution.main_website_distribution.domain_name |
| 94 | + zone_id = aws_cloudfront_distribution.main_website_distribution.hosted_zone_id |
| 95 | + evaluate_target_health = false |
| 96 | + } |
| 97 | +} |
| 98 | + |
0 commit comments