Terraform module to host a static site generated by Publii
This module launches static hosting resources (eg. S3 bucket, Cloudfront) specifically for sites generated by the Static Site Generator Publii
It can in most cases be used to host any static site, however this module adds some configurations for the features of Publii
- Creates an S3 bucket along with an IAM user which has the minimum required permissions to sync from Publii
- Creates a CloudFront endpoint (And optionally ACM certificates and Route53 records in an existing Hosted Zone)
- Creates a Lambda function to run a Cloudfront Invalidation when
sitemap.xml
is created/updated (This file is updated on every sync) - Optionally have CloudFront do the right thing when 'Pretty URLs' are enabled (This is achieved via a CloudFront function which adds
index.html
to the URI if there is no extention) - Optionally redirect from the apex domain (eg. example.com) to www (www.example.com). If this is enabled (
var.cloudfront_enable_apex_to_www_redirect
), the 'Website Url' within 'Server' options should be set to www.yourdomain.com - Publii S3 Server Settings docs (point 26) - Optionally enable WAF
- Optionally add custom origins and cache behaviours
- Full launch with existing Route53 Zone
- Use existing certificate and create own Route53 records
- Adding custom origins and cache behaviours
Name | Version |
---|---|
terraform | >= 1.8.1 |
aws | >= 5.46.0 |
Name | Version |
---|---|
aws | 5.46.0 |
aws.useast1 | 5.46.0 |
random | 3.6.1 |
template | 2.2.0 |
Name | Description | Type | Default | Required |
---|---|---|---|---|
cloudfront_enable_apex_to_www_redirect | Enable CloudFront apex to www redirect | bool |
true |
no |
cloudfront_enable_ipv6 | Enable IPv6 on CloudFront | bool |
true |
no |
cloudfront_enable_waf | Enable CloudFront WAF | bool |
true |
no |
cloudfront_ordered_cache_behaviors | List of ordered_cache_behavior objects. https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution#cache-behavior-arguments | any |
[] |
no |
cloudfront_origins | List of origin objects. https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution#origin-arguments | any |
[] |
no |
cloudfront_tls_certificate_arn | CloudFront TLS certificate ARN (must be created in us-east-1 region) | string |
"" |
no |
enable_publii_pretty_urls | If you hae enabled 'Pretty URLs' in Publii, set this to true | bool |
false |
no |
route53_hosted_zone_options | If you have a Route53 zone, the required DNS records can be created automatically. | object({ |
{ |
no |
s3_bucket_acl | S3 bucket ACL | string |
"private" |
no |
site_url | The desired site URL | string |
n/a | yes |
Name | Description |
---|---|
aws_acm_certificate_cloudfront_frontend | CloudFront frontend's ACM TLS certificate attributes |
aws_cloudfront_distribution_frontend | CloudFront distribution frontend attributes |
aws_cloudfront_distribution_frontend_www_redirect | CloudFront distribution frontend www redirect attributes |
aws_cloudfront_origin_access_identity_frontend | CloudFront frontend's associated origin access identity |
iam_user_publii_s3_frontend | IAM User attributes for Publii S3 bucket |
project_name | Project name. Generated from the site_url and project_random_id |
project_random_id | The random ID generated to ensure unique resource names |
s3_bucket_frontend | S3 bucket frontend attributes |