https://github.com/ventx/terraform-aws-cloudfront-s3-static-site
terraform-aws-cloudfront-s3-static-site
https://github.com/ventx/terraform-aws-cloudfront-s3-static-site
Last synced: 4 months ago
JSON representation
terraform-aws-cloudfront-s3-static-site
- Host: GitHub
- URL: https://github.com/ventx/terraform-aws-cloudfront-s3-static-site
- Owner: ventx
- Created: 2019-02-22T14:10:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-01T16:05:31.000Z (over 7 years ago)
- Last Synced: 2025-09-04T07:32:28.594Z (10 months ago)
- Language: HCL
- Size: 13.7 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Terraform-aws-cloudfront-s3-static-site
## Purpose
Create a static website with S3 bucket as origin and deliver it with a Cloudfront distribution.
### Sidenotes
- The s3 bucket will be created 'private' and no static website hosting will be enabled.
- The certificate and the validation will be made in 'us-east-1' because no other region is currently possible.
- All the arguments with default values are optional
After creating the resource, you have to place your content in your bucket ... that's it.
## Argument Reference
- `site_name`
>Domain name for the new website.
>This is also used to create the name of the bucket and the caller id (current Account ID).
- `create_hosted_zone`
>Optional: If set to 'true' the named root domain will be created. Defaults to 'false'
- `root_domain_name`
>Root domain name for the site
- `index_document`
>Optional: Name of the index file. Defaults to *index.html*
- `error_document`
>Optional: Name of the error file. Defaults to *404.html*
- `is_ipv6_enabled`
>Optional: State of IPv6 for Cloudfront. Defaults to 'true'
- `cdn_min-ttl`
>Optional: Min TTL for Cloudfront distribution. Defaults to '0'
- `cdn_default_ttl`
>Optional: Default TTL for Cloudfront distribution. Defaults to '1000'
- `cdn_max_ttl`
>Optional: Max TTL for Cloudfront distribution. Defaults to '86400'
## Attribute Reference
- `bucket_arn`
>ARN of the used s3 bucket
- `bucket_region`
>AWS Region for the S3 Bucket
- `bucket_name`
>Name of the S3 Bucket
- `site_cdn_arn`
>ARN of the cloudfront distribution
- `site_cdn_domain`
>Domain name of the Cloudfront distribution
- `site_cdn_origin`
>The Cloudfront distribution origin
- `site_certificate_arn`
>ARN of Certificate for the website
- `site_url`
>URL of the static website
## Example Usage
```
// Create your static site with given arguments
module "static_site" {
source = "github.com/ventx/terraform-aws-cloudfront-s3-static-site.git"
site_name = "staticsite.testdomain.com"
root_domain_name = "testdomain.com"
}
// Upload your index.html and 404.html to your S3 Bucket
resource "aws_s3_bucket_object" "index_file" {
bucket = "${module.static_site.bucket_name}"
key = "index.html"
source = "/path/to/index.html"
content_type = "text/html"
}
resource "aws_s3_bucket_object" "error_file" {
bucket = "${module.static_site.bucket_name}"
key = "404.html"
source = "/path/to/404.html"
content_type = "text/html"
```