Skip to content

Commit 9f53010

Browse files
committed
docs: add existing distribution example
1 parent 01189f2 commit 9f53010

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module "fingerprint_cloudfront_integration" {
2+
source = "[email protected]:fingerprintjs/terraform-aws-fingerprint-cloudfront-proxy-integration.git"
3+
4+
fpjs_agent_download_path = var.fpjs_agent_download_path
5+
fpjs_get_result_path = var.fpjs_get_result_path
6+
fpjs_shared_secret = var.fpjs_shared_secret
7+
}

examples/existing-ditribution/main.tf

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 5.57"
6+
}
7+
}
8+
9+
required_version = ">= 1.2.0"
10+
}
11+
12+
provider "aws" {
13+
region = "us-east-1"
14+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
variable "fpjs_shared_secret" {
2+
description = "The proxy secret for the Fingerprint proxy integration"
3+
type = string
4+
}
5+
6+
variable "fpjs_behavior_path" {
7+
description = "All Fingeprint requests will be proxied through this path segment"
8+
type = string
9+
}
10+
11+
variable "fpjs_agent_download_path" {
12+
description = "The Fingerprint agent download will be proxied through this path segment"
13+
type = string
14+
}
15+
16+
variable "fpjs_get_result_path" {
17+
description = "The Fingerprint identification request will be proxied through this path segment"
18+
type = string
19+
}
20+
21+
variable "website_domain" {
22+
description = "The domain for your existing CloudFront distribution, like `yourwebsite.com`"
23+
type = string
24+
}
25+
26+
variable "website_origin_domain_name" {
27+
description = "The main origin of your distribution pointing to your website, like `yourwebsite.s3.amazonaws.com`"
28+
type = string
29+
}
30+
31+
variable "domain_zone_id" {
32+
description = "Zone ID of the domain for your existing CloudFront distribution"
33+
type = string
34+
}
35+
36+
variable "certificate_arn" {
37+
description = "ARN of the domain certificate for your website"
38+
type = string
39+
}
40+
41+

0 commit comments

Comments
 (0)