Terraform script to proxy Plausible through Cloudfront
Niedziela Solutions, LLC's website uses Plausible for analytics.
- Terraform
- AWS Account / Plausible Account
- S3 Bucket with server-side encryption enabled. This is to store the Terraform state remotely in an S3 Bucket.
terraform init -backend-config="profile=YOUR_AWS_PROFILE"
. It will prompt you for the required information.cp environment.tfvars.example environment.tfvars
and change as needed. You'll need to find the IDs for the two managed Cloudfront policies in the AWS Admin under Cloudfront -> Policies. FindCachingDisabled
(Cache) andUserAgentRefererHeaders
(Origin Request) then pull the ID from the URL. You can also remove the configuration for the policies in Terraform and manually set it up then find the drift for it and set the IDs that way.- Verify:
terraform plan -var-file=environment.tfvars
- Invoke:
terraform apply -var-file=environment.tfvars
After the Cloudfront distribution is setup, you can change DNS to point to this Cloudfront distribution for your analytics subdomain.