Skip to content

Commit 417f328

Browse files
committed
chore: update existing distribution example
1 parent dcfc8e6 commit 417f328

File tree

8 files changed

+95
-61
lines changed

8 files changed

+95
-61
lines changed

examples/existing-ditribution/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ To quickly run the example for testing purposes, you can:
1313
3. Run `terraform plan`.
1414
4. Run `terraform apply`.
1515

16+
The domain-related resources and variables are commented out for simplicity but you uncomment them or use just them as a reference.
17+
1618
### Using in production
1719

1820
This is a simplified example. Use it as a reference but make sure to **adjust the code to your needs and security practices** before deploying it to production environments.

examples/existing-ditribution/main.tf

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
# Example CloudFront Distribution. DO NOT USE AS-IS, and make sure to follow best practices before releasing to the production.
1+
2+
locals {
3+
# TODO: When adapting this example, replace this with your actual website origin (directly or through a `terraform.tfvars` file)
4+
website_origin_domain_name = "yourwebsite.com"
5+
# TODO: When adapting this example, replace this with the path segment you want for your proxy integration (directly or through a `terraform.tfvars` file)
6+
# Avoid ad blocker triggers like "fingerprint", "track", etc., random value is best
7+
fpjs_behavior_path = "metrics"
8+
}
9+
10+
# Example CloudFront Distribution.
11+
# DO NOT USE AS-IS, Make sure to adjust the code to your needs and security practices before releasing to production.
212
resource "aws_cloudfront_distribution" "main_website_distribution" {
313
enabled = true
414
is_ipv6_enabled = true
5-
comment = "CloudFront distribution for ${var.website_origin_domain_name}"
15+
comment = "CloudFront distribution for ${local.website_origin_domain_name}"
616
default_root_object = "index.html"
717

818
origin {
9-
domain_name = var.website_origin_domain_name
19+
domain_name = local.website_origin_domain_name
1020
origin_id = "your-website"
1121

1222
custom_origin_config {
@@ -41,13 +51,6 @@ resource "aws_cloudfront_distribution" "main_website_distribution" {
4151
}
4252
}
4353

44-
aliases = [var.website_domain]
45-
46-
viewer_certificate {
47-
acm_certificate_arn = var.certificate_arn
48-
ssl_support_method = "sni-only"
49-
}
50-
5154
#region Fingerprint CloudFront Integration start
5255
origin {
5356
domain_name = module.fingerprint_cloudfront_integration.fpjs_origin_name
@@ -65,7 +68,7 @@ resource "aws_cloudfront_distribution" "main_website_distribution" {
6568
}
6669

6770
ordered_cache_behavior {
68-
path_pattern = "${var.fpjs_behavior_path}/*"
71+
path_pattern = "${local.fpjs_behavior_path}/*"
6972

7073
allowed_methods = ["GET", "HEAD", "OPTIONS", "PUT", "POST", "PATCH", "DELETE"]
7174
cached_methods = ["GET", "HEAD"]
@@ -82,18 +85,34 @@ resource "aws_cloudfront_distribution" "main_website_distribution" {
8285
}
8386
}
8487
#endregion
85-
}
86-
87-
88-
resource "aws_route53_record" "apex_domain" {
89-
zone_id = var.domain_zone_id
90-
name = var.website_domain
91-
type = "A"
9288

93-
alias {
94-
name = aws_cloudfront_distribution.main_website_distribution.domain_name
95-
zone_id = aws_cloudfront_distribution.main_website_distribution.hosted_zone_id
96-
evaluate_target_health = false
89+
viewer_certificate {
90+
cloudfront_default_certificate = true
9791
}
92+
93+
# You can serve the distribution from your own domain
94+
# - Uncomment the `aliases` and `viewer_certificate` below
95+
# - Uncomment the 'aws_route53_record' below
96+
# - Uncomment the DNS-related variables in `variables.tf`
97+
# - Define the referenced variables in a `terraform.tfvars` file
98+
# - Remove the default `viewer_certificate` above
99+
100+
# aliases = [var.website_domain]
101+
# viewer_certificate {
102+
# acm_certificate_arn = var.certificate_arn
103+
# ssl_support_method = "sni-only"
104+
# }
98105
}
99106

107+
# resource "aws_route53_record" "apex_domain" {
108+
# zone_id = var.domain_zone_id
109+
# name = var.website_domain
110+
# type = "A"
111+
112+
# alias {
113+
# name = aws_cloudfront_distribution.main_website_distribution.domain_name
114+
# zone_id = aws_cloudfront_distribution.main_website_distribution.hosted_zone_id
115+
# evaluate_target_health = false
116+
# }
117+
# }
118+
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fpjs_shared_secret = "YOUR_PROXY_SECRET_CREATED_IN_FINGERPRINT_DASHBOARD"
22
fpjs_agent_download_path = "463N7"
33
fpjs_get_result_path = "r35U17"
4-
fpjs_behavior_path = "fpj5"
5-
domain_zone_id = "ZONE_ID_OF_YOUR_DOMAIN_IN_AWS"
6-
website_domain = "yourwebsite.com"
7-
website_origin_domain_name = "your-website-origin.s3.amazonaws.com"
8-
certificate_arn = "ARN_OF_THE_CERTIFICATE_OF_YOUR_DOMAIN_IN_AWS"
4+
# fpjs_behavior_path = "fpj5"
5+
# domain_zone_id = "ZONE_ID_OF_YOUR_DOMAIN_IN_AWS"
6+
# website_domain = "yourwebsite.com"
7+
# website_origin_domain_name = "your-website-origin.s3.amazonaws.com"
8+
# certificate_arn = "ARN_OF_THE_CERTIFICATE_OF_YOUR_DOMAIN_IN_AWS"

examples/existing-ditribution/variables.tf

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,50 @@ variable "fpjs_shared_secret" {
44
type = string
55
}
66

7-
variable "fpjs_behavior_path" {
8-
// https://dev.fingerprint.com/docs/cloudfront-proxy-integration-v2#step-2-create-path-variables
9-
description = "All Fingeprint requests will be proxied through this path segment"
10-
type = string
11-
}
12-
137
variable "fpjs_agent_download_path" {
148
// https://dev.fingerprint.com/docs/cloudfront-proxy-integration-v2#step-2-create-path-variables
159
description = "The Fingerprint agent download will be proxied through this path segment"
1610
type = string
11+
default = "agent"
1712
}
1813

1914
variable "fpjs_get_result_path" {
2015
// https://dev.fingerprint.com/docs/cloudfront-proxy-integration-v2#step-2-create-path-variables
2116
description = "The Fingerprint identification request will be proxied through this path segment"
2217
type = string
18+
default = "result"
2319
}
2420

25-
variable "website_domain" {
26-
description = "The domain for your existing CloudFront distribution, like `yourwebsite.com`"
27-
type = string
28-
}
21+
/**
22+
* The following variables are only relevant for this example.
23+
* - They are not required for the module itself
24+
* - They are optional, uncomment them out if you want to adapt the example including adding a domain for the CloudFront distribution
25+
*/
2926

30-
variable "website_origin_domain_name" {
31-
description = "The main origin of your distribution pointing to your website, like `yourwebsite.s3.amazonaws.com`"
32-
type = string
33-
}
27+
# variable "fpjs_behavior_path" {
28+
# // https://dev.fingerprint.com/docs/cloudfront-proxy-integration-v2#step-2-create-path-variables
29+
# description = "All Fingeprint requests will be proxied through this path segment"
30+
# type = string
31+
# }
3432

35-
variable "domain_zone_id" {
36-
description = "Zone ID of the domain for your existing CloudFront distribution"
37-
type = string
38-
}
33+
# variable "website_domain" {
34+
# description = "The domain for your existing CloudFront distribution, like `yourwebsite.com`"
35+
# type = string
36+
# }
3937

40-
variable "certificate_arn" {
41-
description = "ARN of the domain certificate for your website"
42-
type = string
43-
}
38+
# variable "website_origin_domain_name" {
39+
# description = "The main origin of your distribution pointing to your website, like `yourwebsite.s3.amazonaws.com`"
40+
# type = string
41+
# }
42+
43+
# variable "domain_zone_id" {
44+
# description = "Zone ID of the domain for your existing CloudFront distribution"
45+
# type = string
46+
# }
47+
48+
# variable "certificate_arn" {
49+
# description = "ARN of the domain certificate for your website"
50+
# type = string
51+
# }
4452

4553

examples/standalone-distribution/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ To quickly run the example for testing purposes, you can:
1313
3. Run `terraform plan`.
1414
4. Run `terraform apply`.
1515

16+
The domain-related resources and variables are commented out for simplicity but you uncomment them or use just them as a reference.
17+
1618
### Using in production
1719

1820
This is a simplified example. Use it as a reference but make sure to **adjust the code to your needs and security practices** before deploying it to production environments.

examples/standalone-distribution/cloudfront_distribution.tf

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Example CloudFront Distribution. DO NOT USE AS-IS, and make sure to follow best practices before releasing to the production.
1+
# Example CloudFront Distribution.
2+
# DO NOT USE AS-IS, Make sure to adjust the code to your needs and security practices before releasing to production.
23
resource "aws_cloudfront_distribution" "fpjs_cloudfront_distribution" {
34
comment = "Fingerprint proxy integration distribution (created via Terraform)"
45

@@ -51,9 +52,12 @@ resource "aws_cloudfront_distribution" "fpjs_cloudfront_distribution" {
5152
cloudfront_default_certificate = true
5253
}
5354

54-
# You can make the distribution available on a subdomain of your website
55-
# - Uncomment the following and define the referenced variables in a `terraform.tfvars` file
56-
# - Remove the default viewer certificate above
55+
# You can serve the distribution from a subdomain of your website
56+
# - Uncomment the `aliases` and `viewer_certificate` below
57+
# - Uncomment the 'aws_route53_record' below
58+
# - Uncomment the variables in `variables.tf`
59+
# - Define the referenced variables in a `terraform.tfvars` file
60+
# - Remove the default `viewer_certificate` above
5761

5862
# aliases = [var.proxy_subdomain_domain]
5963
# viewer_certificate {
@@ -62,9 +66,6 @@ resource "aws_cloudfront_distribution" "fpjs_cloudfront_distribution" {
6266
# }
6367
}
6468

65-
# You can make the distribution available on a subdomain of your website
66-
# - Uncomment the following and define the referenced variables in a `terraform.tfvars` file
67-
6869
# resource "aws_route53_record" "cloudfront_terraform_new_distribution_record" {
6970
# zone_id = var.domain_zone_id
7071
# name = var.proxy_subdomain_domain
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fpjs_shared_secret = "YOUR_PROXY_SECRET_CREATED_IN_FINGERPRINT_DASHBOARD"
22
fpjs_agent_download_path = "463N7"
33
fpjs_get_result_path = "r35U17"
4-
domain_zone_id = "ZONE_ID_OF_YOUR_DOMAIN_IN_AWS"
5-
proxy_subdomain_domain = "metrics.yourwebsite.com"
6-
certificate_arn = "ARN_OF_THE_CERTIFICATE_OF_YOUR_DOMAIN_IN_AWS"
4+
# domain_zone_id = "ZONE_ID_OF_YOUR_DOMAIN_IN_AWS"
5+
# proxy_subdomain_domain = "metrics.yourwebsite.com"
6+
# certificate_arn = "ARN_OF_THE_CERTIFICATE_OF_YOUR_DOMAIN_IN_AWS"

examples/standalone-distribution/variables.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@ variable "fpjs_agent_download_path" {
88
// https://dev.fingerprint.com/docs/cloudfront-proxy-integration-v2#step-2-create-path-variables
99
description = "The Fingerprint agent download will be proxied through this path"
1010
type = string
11+
default = "agent"
1112
}
1213

1314
variable "fpjs_get_result_path" {
1415
// https://dev.fingerprint.com/docs/cloudfront-proxy-integration-v2#step-2-create-path-variables
1516
description = "The Fingerprint identification request will be proxied through this path"
1617
type = string
18+
default = "result"
1719
}
1820

1921
/**
2022
* The following variables are only relevant for this example.
21-
* - They are not relevant to the module itself
22-
* - They are optional, uncomment them out if you want to add a subdomain for the CloudFront distribution
23+
* - They are not requiered for the module itself
24+
* - They are optional, uncomment them out if you want adapt the example including adding a subdomain for the CloudFront distribution
2325
*/
2426

2527
# variable "proxy_subdomain_domain" {

0 commit comments

Comments
 (0)