Using example.com as the input domain, this module will:
- Create a Route53 zone for example.com
- Create a bucket named example.com
- Create a bucket named www.example.com
- Create a Route53 A record example.com for the static website bucket of example.com
- Create a Route53 A record www.example.com for the static website bucket of www.example.com
This is possibly the simplest way of sending traffic from one domain to another using AWS services. The only caveat is that two bucket names needs to be available on AWS S3.
- Put main.tf in a module folder, for example
modules/site-redirect/main.tf
Use module like this within your terraform plan:
module "redirect_example_com" {
source = "modules/site-redirect"
domain = "example.com"
redirect = "https://send.traffic.here.example.com"
# Accepts a provider, if you have multiple defined
providers {
"aws" = "aws"
}
}
Credits and inspiration:
Works great other than for https you also need a Cloudfront resource
Amazon S3 website endpoints do not support HTTPS or access points. If you want to use HTTPS, you can use Amazon CloudFront to serve a static website hosted on Amazon S3.