Infra & Cloud
terraform
Intermediate
AWS CloudFront + S3 CDN
Terraform to serve an S3 static site through CloudFront with HTTPS and caching.
terraform
resource "aws_cloudfront_distribution" "cdn" {
origin {
domain_name = aws_s3_bucket.site.bucket_regional_domain_name
origin_id = "s3-origin"
}
enabled = true
default_root_object = "index.html"
default_cache_behavior {
viewer_protocol_policy = "redirect-to-https"
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]
target_origin_id = "s3-origin"
forwarded_values { query_string = false; cookies { forward = "none" } }
}
viewer_certificate { cloudfront_default_certificate = true }
}
Prerequisites
- terraform >= 1.0
- AWS provider
- S3 bucket
Pro Tips
- → Invalidate cache with aws cloudfront create-invalidation after deploy.
Commercial Licensing
Acquire a production access token or template license for enterprise deployment.
Module Info
- Language
- terraform
- Level
- Intermediate
- Read time
- 5 min
- Published
- Dec 2025
- License
- Commercial License
Newsletter
New modules every week, directly to your inbox.
Similar Modules
AWS S3 Static Website
Terraform module to provision an S3 bucket for static website hosting.
terraform
·
Intermediate
AWS RDS Postgres Terraform
Terraform resource for an RDS PostgreSQL instance with encryption and backup.
terraform
·
Intermediate
ECS Task Force Stop
Force-stop all running ECS tasks in a service for emergency rollback.
bash
·
Intermediate