Write a Terraform module for generating the infrastructure needed for hosting a static website/app on AWS.
- Storing the static site content
- Serving the content with a CDN
- Providing hosted zone and cname for the site
- Creating multiple separate environments - E.g. make it easy to deploy to new environments without manual work in AWS UI
- Reuse without changing/removing hard-coded strings within the resource blocks
- Providing inputs/outputs so that the code could be invoked from a CI or other system
- Cloudwatch resources to help monitor the site
- WAF for providing additional security capabilities
- Log delivery to S3/Athena for downstream analysis
- Integration (even partial) with any of the AWS Code* CI/CD tools
AWS resources for Terraform Module local development are under the local
directory.
- Copy
pedro.tfvars
file naming it after the user. - Modify the new file to create a new subdomain on a domain you control.
- Run Terraform via:
- Prepare Terraform using
terraform init
- Plan the Terraform changes and review using
terraform plan -var-file <yourname>.tfvars -out tfplan
- Apply Terraform changes via
terraform apply tfplan
- Prepare Terraform using
- Add a NS records on the domain your control for the new Route53 Hosted Zone. The NS record should have the same name as your Hosted Zone. Use the Terraform output for the answers, depending on the DNS host it can a single or multiple answers.
The Terraform module is been used by 2 environments, dev
and prd
. We can only upload new static site content by creating a new version and host it on the dev
environment. Once happy with the current dev
version it must then be promoted to prd
.
- Create a new static site version with
./do.sh version-up <version>
. - Test and accept the version in the
dev
environment. - Promote the static site artifact from
dev
toprd
with./do.sh promote
.