S3_CloudFront_Webdeployment
Secure static website dynamically deploy it with Terraform hosted in AWS
Cloud - ☁️
IaaC
AWS S3 and CloudFront architecture diagram
Note
module.static_web_01 will be creating resource such AWS Cloudfront distribution for an S3 bucket with web static files.
module.static_web_02 will be creating resource such AWS Cloudfront origin OAI for an S3 bucket with web static files.
Proper security policies for S3 buckets and CloudFront are still require in both deployments.
Purpose
Shows how to use AWS with Terraform to accomplish the following tasks:
- Create one or multiple S3 buckets to storage/host static web files
- Create a CloudFront for a fast content delivery network (CDN)
Prerequisites
- You must have an AWS account, and have your default credentials and AWS Region configured
- You must have Terraform installed
- You must create static files (HTML, CSS, JavaScript) and storage them in your bucket
Cautions
- As an AWS best practice, grant this code least privilege, or only the permissions required to perform a task. For more information, see Grant Least Privilege in the AWS Identity and Access Management User Guide.
- This code has been tested in us-east-1 AWS Regions only. However it should work in any other region.
- Running this code might result in charges to your AWS account.
How to run this code
- Clone this repo
- cd to S3_CloudFront_Webdeployment folder
- terraform init
- terraform plan
- terraform validate
- terraform apply
- Alternate command : terraform apply -auto-approve
- terraform destroy
- Alternate command : terraform destroy -auto-approve
- terraform fmt # A way to format the terraform code
