This is a Terraform module designed to automate the deploy of a static website.
This modules creates the following resources:
- two S3 buckets, one for the content (
www.example.com
), one for redirecting from the naked domain to www (namedexample.com
) - two CloudFront distribution, one per bucket, that also redirect from HTTP to HTTPS
- two Route53 alias records, one per CloudFront distribution
You have to create a SSL certificate for both domains (www and naked) on AWS. This step can't be automated, due to limitations of the AWS API.
Follow this instructions:
- Access the Certificate Manager on the AWS console
- Switch to the
us-east-1
(N. Virginia) region.- 🚨 This is CRUCIAL, as AWS requires certificates for CloudFront to be issued in this region
- Click on "Request a certificate"
- Enter as a primary domain name the domain you want with www, for example:
www.buildo.io
- Enter the naked domain as an additional domain name, for example
buildo.io
You should be in this situation:
NOTE: www
domain must come first!
- Follow the steps for verifying the domain
Using the module is as simple as:
provider "aws" {
region = "eu-west-1" // The region for the S3 buckets and the CloudFront distribution
}
module "website" {
source = "buildo/website/aws"
domain = "mysite.com" // no www here
# optional: enable health check on www.mysite.com
enable_health_check = true
health_check_alarm_sns_topics = [
"<arn of a topic to notify for health check alarms>"
]
}