Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Simplify examples to avoid confusion in the registry #38

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/existing-ditribution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ To quickly run the example for testing purposes, you can:
3. Run `terraform plan`.
4. Run `terraform apply`.

The domain-related resources and variables are commented out for simplicity but you uncomment them or use just them as a reference.
necipallef marked this conversation as resolved.
Show resolved Hide resolved

### Using in production

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.
Expand Down
2 changes: 1 addition & 1 deletion examples/existing-ditribution/fingerprint.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "fingerprint_cloudfront_integration" {
source = "fingerprintjs/fingerprint-cloudfront-proxy-integration/aws"
source = "../.."

fpjs_agent_download_path = var.fpjs_agent_download_path
fpjs_get_result_path = var.fpjs_get_result_path
Expand Down
63 changes: 41 additions & 22 deletions examples/existing-ditribution/main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
# Example CloudFront Distribution. DO NOT USE AS-IS, and make sure to follow best practices before releasing to the production.

locals {
# TODO: When adapting this example, replace this with your actual website origin (directly or through a `terraform.tfvars` file)
website_origin_domain_name = "yourwebsite.com"
# TODO: When adapting this example, replace this with the path segment you want for your proxy integration (directly or through a `terraform.tfvars` file)
# Avoid ad blocker triggers like "fingerprint", "track", etc., random value is best
fpjs_behavior_path = "metrics"
necipallef marked this conversation as resolved.
Show resolved Hide resolved
}

# Example CloudFront Distribution.
# DO NOT USE AS-IS, Make sure to adjust the code to your needs and security practices before releasing to production.
resource "aws_cloudfront_distribution" "main_website_distribution" {
enabled = true
is_ipv6_enabled = true
comment = "CloudFront distribution for ${var.website_origin_domain_name}"
comment = "CloudFront distribution for ${local.website_origin_domain_name}"
default_root_object = "index.html"

origin {
domain_name = var.website_origin_domain_name
domain_name = local.website_origin_domain_name
origin_id = "your-website"

custom_origin_config {
Expand Down Expand Up @@ -41,13 +51,6 @@ resource "aws_cloudfront_distribution" "main_website_distribution" {
}
}

aliases = [var.website_domain]

viewer_certificate {
acm_certificate_arn = var.certificate_arn
ssl_support_method = "sni-only"
}

#region Fingerprint CloudFront Integration start
origin {
domain_name = module.fingerprint_cloudfront_integration.fpjs_origin_name
Expand All @@ -65,7 +68,7 @@ resource "aws_cloudfront_distribution" "main_website_distribution" {
}

ordered_cache_behavior {
path_pattern = "${var.fpjs_behavior_path}/*"
path_pattern = "${local.fpjs_behavior_path}/*"

allowed_methods = ["GET", "HEAD", "OPTIONS", "PUT", "POST", "PATCH", "DELETE"]
cached_methods = ["GET", "HEAD"]
Expand All @@ -82,18 +85,34 @@ resource "aws_cloudfront_distribution" "main_website_distribution" {
}
}
#endregion
}


resource "aws_route53_record" "apex_domain" {
zone_id = var.domain_zone_id
name = var.website_domain
type = "A"

alias {
name = aws_cloudfront_distribution.main_website_distribution.domain_name
zone_id = aws_cloudfront_distribution.main_website_distribution.hosted_zone_id
evaluate_target_health = false
viewer_certificate {
cloudfront_default_certificate = true
}

# You can serve the distribution from your own domain
# - Uncomment the `aliases` and `viewer_certificate` below
# - Uncomment the 'aws_route53_record' below
# - Uncomment the DNS-related variables in `variables.tf`
# - Define the referenced variables in a `terraform.tfvars` file
# - Remove the default `viewer_certificate` above

# aliases = [var.website_domain]
# viewer_certificate {
# acm_certificate_arn = var.certificate_arn
# ssl_support_method = "sni-only"
# }
}

# resource "aws_route53_record" "apex_domain" {
# zone_id = var.domain_zone_id
# name = var.website_domain
# type = "A"

# alias {
# name = aws_cloudfront_distribution.main_website_distribution.domain_name
# zone_id = aws_cloudfront_distribution.main_website_distribution.hosted_zone_id
# evaluate_target_health = false
# }
# }

10 changes: 5 additions & 5 deletions examples/existing-ditribution/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fpjs_shared_secret = "YOUR_PROXY_SECRET_CREATED_IN_FINGERPRINT_DASHBOARD"
fpjs_agent_download_path = "463N7"
fpjs_get_result_path = "r35U17"
fpjs_behavior_path = "fpj5"
domain_zone_id = "ZONE_ID_OF_YOUR_DOMAIN_IN_AWS"
website_domain = "yourwebsite.com"
website_origin_domain_name = "your-website-origin.s3.amazonaws.com"
certificate_arn = "ARN_OF_THE_CERTIFICATE_OF_YOUR_DOMAIN_IN_AWS"
# fpjs_behavior_path = "fpj5"
# domain_zone_id = "ZONE_ID_OF_YOUR_DOMAIN_IN_AWS"
# website_domain = "yourwebsite.com"
# website_origin_domain_name = "your-website-origin.s3.amazonaws.com"
# certificate_arn = "ARN_OF_THE_CERTIFICATE_OF_YOUR_DOMAIN_IN_AWS"
52 changes: 30 additions & 22 deletions examples/existing-ditribution/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,50 @@ variable "fpjs_shared_secret" {
type = string
}

variable "fpjs_behavior_path" {
// https://dev.fingerprint.com/docs/cloudfront-proxy-integration-v2#step-2-create-path-variables
description = "All Fingeprint requests will be proxied through this path segment"
type = string
}

variable "fpjs_agent_download_path" {
// https://dev.fingerprint.com/docs/cloudfront-proxy-integration-v2#step-2-create-path-variables
description = "The Fingerprint agent download will be proxied through this path segment"
type = string
default = "agent"
}

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

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

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

variable "domain_zone_id" {
description = "Zone ID of the domain for your existing CloudFront distribution"
type = string
}
# variable "website_domain" {
# description = "The domain for your existing CloudFront distribution, like `yourwebsite.com`"
# type = string
# }

variable "certificate_arn" {
description = "ARN of the domain certificate for your website"
type = string
}
# variable "website_origin_domain_name" {
# description = "The main origin of your distribution pointing to your website, like `yourwebsite.s3.amazonaws.com`"
# type = string
# }

# variable "domain_zone_id" {
# description = "Zone ID of the domain for your existing CloudFront distribution"
# type = string
# }

# variable "certificate_arn" {
# description = "ARN of the domain certificate for your website"
# type = string
# }


2 changes: 2 additions & 0 deletions examples/standalone-distribution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ To quickly run the example for testing purposes, you can:
3. Run `terraform plan`.
4. Run `terraform apply`.

The domain-related resources and variables are commented out for simplicity but you uncomment them or use just them as a reference.
necipallef marked this conversation as resolved.
Show resolved Hide resolved

### Using in production

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.
Expand Down
35 changes: 19 additions & 16 deletions examples/standalone-distribution/cloudfront_distribution.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Example CloudFront Distribution. DO NOT USE AS-IS, and make sure to follow best practices before releasing to the production.
# Example CloudFront Distribution.
# DO NOT USE AS-IS, Make sure to adjust the code to your needs and security practices before releasing to production.
resource "aws_cloudfront_distribution" "fpjs_cloudfront_distribution" {
comment = "Fingerprint proxy integration distribution (created via Terraform)"

Expand Down Expand Up @@ -47,26 +48,28 @@ resource "aws_cloudfront_distribution" "fpjs_cloudfront_distribution" {
}
}

aliases = [var.proxy_subdomain_domain]
viewer_certificate {
acm_certificate_arn = var.certificate_arn
ssl_support_method = "sni-only"
cloudfront_default_certificate = true
}

# If don't want to serve the distribution from a subdomain for now, use the default certificate instead
# (comment out `viewer_certificate` and `aliases` above and use the `viewer_certificate` below)
# You can serve the distribution from a subdomain of your website
# - Uncomment the `aliases` and `viewer_certificate` below
# - Uncomment the 'aws_route53_record' below
# - Uncomment the variables in `variables.tf`
# - Define the referenced variables in a `terraform.tfvars` file
# - Remove the default `viewer_certificate` above

# aliases = [var.proxy_subdomain_domain]
# viewer_certificate {
# cloudfront_default_certificate = true
# acm_certificate_arn = var.certificate_arn
# ssl_support_method = "sni-only"
# }
}

# You can make the distribution available on a subdomain of your website
# (comment this out if you don't want to do that for now)
resource "aws_route53_record" "cloudfront_terraform_new_distribution_record" {
zone_id = var.domain_zone_id
name = var.proxy_subdomain_domain
type = "CNAME"
ttl = 300
records = [aws_cloudfront_distribution.fpjs_cloudfront_distribution.domain_name]
}
# resource "aws_route53_record" "cloudfront_terraform_new_distribution_record" {
# zone_id = var.domain_zone_id
# name = var.proxy_subdomain_domain
# type = "CNAME"
# ttl = 300
# records = [aws_cloudfront_distribution.fpjs_cloudfront_distribution.domain_name]
# }
2 changes: 1 addition & 1 deletion examples/standalone-distribution/fingerprint.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "fingerprint_cloudfront_integration" {
source = "fingerprintjs/fingerprint-cloudfront-proxy-integration/aws"
source = "../.."

fpjs_agent_download_path = var.fpjs_agent_download_path
fpjs_get_result_path = var.fpjs_get_result_path
Expand Down
6 changes: 3 additions & 3 deletions examples/standalone-distribution/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fpjs_shared_secret = "YOUR_PROXY_SECRET_CREATED_IN_FINGERPRINT_DASHBOARD"
fpjs_agent_download_path = "463N7"
fpjs_get_result_path = "r35U17"
domain_zone_id = "ZONE_ID_OF_YOUR_DOMAIN_IN_AWS"
proxy_subdomain_domain = "metrics.yourwebsite.com"
certificate_arn = "ARN_OF_THE_CERTIFICATE_OF_YOUR_DOMAIN_IN_AWS"
# domain_zone_id = "ZONE_ID_OF_YOUR_DOMAIN_IN_AWS"
# proxy_subdomain_domain = "metrics.yourwebsite.com"
# certificate_arn = "ARN_OF_THE_CERTIFICATE_OF_YOUR_DOMAIN_IN_AWS"
31 changes: 19 additions & 12 deletions examples/standalone-distribution/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,33 @@ variable "fpjs_agent_download_path" {
// https://dev.fingerprint.com/docs/cloudfront-proxy-integration-v2#step-2-create-path-variables
description = "The Fingerprint agent download will be proxied through this path"
type = string
default = "agent"
}

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

variable "proxy_subdomain_domain" {
description = "The subdomain for the CloudFront distribution, including the root domain of your website, for example `metrics.yourwebsite.com`"
type = string
}
/**
* The following variables are only relevant for this example.
* - They are not requiered for the module itself
* - They are optional, uncomment them out if you want adapt the example including adding a subdomain for the CloudFront distribution
*/

# variable "proxy_subdomain_domain" {
# description = "The subdomain for the CloudFront distribution, including the root domain of your website, for example `metrics.yourwebsite.com`"
# type = string
# }

variable "domain_zone_id" {
description = "Zone ID of the domain for the CloudFront distribution"
type = string
}
# variable "domain_zone_id" {
# description = "Zone ID of the domain for the CloudFront distribution"
# type = string
# }

variable "certificate_arn" {
description = "ARN of the domain certificate for the CloudFront distribution"
type = string
}
# variable "certificate_arn" {
# description = "ARN of the domain certificate for the CloudFront distribution"
# type = string
# }
Loading