Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ import VersionBadge from '../../../../../src/components/VersionBadge.tsx';
import { HclListItem, HclListItemDescription, HclListItemTypeDetails, HclListItemDefaultValue, HclGeneralListItem } from '../../../../../src/components/HclListItem.tsx';
import { ModuleUsage } from "../../../../../src/components/ModuleUsage";

<VersionBadge repoTitle="Static Assets Modules" version="0.17.5" lastModifiedVersion="0.17.5"/>
<VersionBadge repoTitle="Static Assets Modules" version="0.17.4" lastModifiedVersion="0.17.4"/>

# S3 CloudFront Module

<a href="https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/modules/s3-cloudfront" className="link-button" title="View the source code for this module in GitHub.">View Source</a>
<a href="https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/modules/s3-cloudfront" className="link-button" title="View the source code for this module in GitHub.">View Source</a>

<a href="https://github.com/gruntwork-io/terraform-aws-static-assets/releases/tag/v0.17.5" className="link-button" title="Release notes for only versions which impacted this module.">Release Notes</a>
<a href="https://github.com/gruntwork-io/terraform-aws-static-assets/releases/tag/v0.17.4" className="link-button" title="Release notes for only versions which impacted this module.">Release Notes</a>

This module deploys a [CloudFront](https://aws.amazon.com/cloudfront/) distribution as a Content Distribution Network
(CDN) in front of an [S3 bucket](https://aws.amazon.com/s3/). This reduces latency for your users, by caching your
static content in servers around the world. It also allows you to use SSL with the static content in an S3 bucket.

See the [s3-static-website module](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/modules/s3-static-website) for how to deploy static content in an S3 bucket.
See the [s3-static-website module](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/modules/s3-static-website) for how to deploy static content in an S3 bucket.

## Quick Start

* See the [cloudfront-s3-public](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/examples/cloudfront-s3-public) and
[cloudfront-s3-private](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/examples/cloudfront-s3-private) examples for working sample code.
* Check out [vars.tf](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/modules/s3-cloudfront/vars.tf) for all parameters you can set for this module.
* See the [cloudfront-s3-public](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/examples/cloudfront-s3-public) and
[cloudfront-s3-private](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/examples/cloudfront-s3-private) examples for working sample code.
* Check out [vars.tf](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/modules/s3-cloudfront/vars.tf) for all parameters you can set for this module.

## Public vs private S3 buckets

Expand Down Expand Up @@ -130,7 +130,7 @@ most use cases, but is not particularly flexible. In particular, the limitations
* Only one default cache behavior is supported
([cache behaviors](https://www.terraform.io/docs/providers/aws/r/cloudfront_distribution.html#cache-behavior-arguments)
is an inline block). You can control the default cache settings using a number of parameters, including
`cached_methods`, `default_ttl`, `min_ttl`, `max_ttl`, and many others (see [vars.tf](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/modules/s3-cloudfront/vars.tf) for the full list).
`cached_methods`, `default_ttl`, `min_ttl`, `max_ttl`, and many others (see [vars.tf](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/modules/s3-cloudfront/vars.tf) for the full list).

* Only two error responses are supported
([error responses](https://www.terraform.io/docs/providers/aws/r/cloudfront_distribution.html#custom-error-response-arguments)
Expand Down Expand Up @@ -162,7 +162,7 @@ into your own codebase, using it as a guide, and adding the tweaks you need.

module "s_3_cloudfront" {

source = "git::git@github.com:gruntwork-io/terraform-aws-static-assets.git//modules/s3-cloudfront?ref=v0.17.5"
source = "git::git@github.com:gruntwork-io/terraform-aws-static-assets.git//modules/s3-cloudfront?ref=v0.17.4"

# ----------------------------------------------------------------------------------------------------
# REQUIRED VARIABLES
Expand Down Expand Up @@ -300,9 +300,6 @@ module "s_3_cloudfront" {
# The error responses you want CloudFront to return to the viewer.
error_responses = null

# The name of an existing logging bucket to use instead of creating.
existing_s3_log_bucket_name = null

# The website endpoints for each failover S3 bucket. This value of each should
# be of the format <BUCKET_NAME>.s3-website-<AWS_REGION>.amazonaws.com. Only
# used if var.s3_bucket_is_public_website is true, and if you are providing a
Expand Down Expand Up @@ -424,10 +421,6 @@ module "s_3_cloudfront" {
# var.acm_certificate_arn, or var.iam_certificate_id.
use_cloudfront_default_certificate = true

# Enable the use of CloudFront OAC. Enabling the use of OAC will disable
# Origin Access Identity (OAI)
use_cloudfront_origin_access_control = false

# Use this element to specify the protocol that users can use to access the
# files in the origin specified by TargetOriginId when a request matches the
# path pattern in PathPattern. One of allow-all, https-only, or
Expand Down Expand Up @@ -462,7 +455,7 @@ module "s_3_cloudfront" {
# ------------------------------------------------------------------------------------------------------

terraform {
source = "git::git@github.com:gruntwork-io/terraform-aws-static-assets.git//modules/s3-cloudfront?ref=v0.17.5"
source = "git::git@github.com:gruntwork-io/terraform-aws-static-assets.git//modules/s3-cloudfront?ref=v0.17.4"
}

inputs = {
Expand Down Expand Up @@ -603,9 +596,6 @@ inputs = {
# The error responses you want CloudFront to return to the viewer.
error_responses = null

# The name of an existing logging bucket to use instead of creating.
existing_s3_log_bucket_name = null

# The website endpoints for each failover S3 bucket. This value of each should
# be of the format <BUCKET_NAME>.s3-website-<AWS_REGION>.amazonaws.com. Only
# used if var.s3_bucket_is_public_website is true, and if you are providing a
Expand Down Expand Up @@ -727,10 +717,6 @@ inputs = {
# var.acm_certificate_arn, or var.iam_certificate_id.
use_cloudfront_default_certificate = true

# Enable the use of CloudFront OAC. Enabling the use of OAC will disable
# Origin Access Identity (OAI)
use_cloudfront_origin_access_control = false

# Use this element to specify the protocol that users can use to access the
# files in the origin specified by TargetOriginId when a request matches the
# path pattern in PathPattern. One of allow-all, https-only, or
Expand Down Expand Up @@ -1115,15 +1101,6 @@ The error responses you want CloudFront to return to the viewer.
<HclListItemDefaultValue defaultValue="null"/>
</HclListItem>

<HclListItem name="existing_s3_log_bucket_name" requirement="optional" type="string">
<HclListItemDescription>

The name of an existing logging bucket to use instead of creating.

</HclListItemDescription>
<HclListItemDefaultValue defaultValue="null"/>
</HclListItem>

<HclListItem name="failover_bucket_website_endpoints" requirement="optional" type="list(string)">
<HclListItemDescription>

Expand Down Expand Up @@ -1369,15 +1346,6 @@ Set to true if you want viewers to use HTTPS to request your objects and you're
<HclListItemDefaultValue defaultValue="true"/>
</HclListItem>

<HclListItem name="use_cloudfront_origin_access_control" requirement="optional" type="bool">
<HclListItemDescription>

Enable the use of CloudFront OAC. Enabling the use of OAC will disable Origin Access Identity (OAI)

</HclListItemDescription>
<HclListItemDefaultValue defaultValue="false"/>
</HclListItem>

<HclListItem name="viewer_protocol_policy" requirement="optional" type="string">
<HclListItemDescription>

Expand Down Expand Up @@ -1432,9 +1400,6 @@ If you have specified whitelist in <a href="#forward_cookies"><code>forward_cook
<HclListItem name="cloudfront_id">
</HclListItem>

<HclListItem name="cloudfront_origin_access_control_id">
</HclListItem>

<HclListItem name="cloudfront_origin_access_identity_iam_arn">
</HclListItem>

Expand All @@ -1448,11 +1413,11 @@ If you have specified whitelist in <a href="#forward_cookies"><code>forward_cook
<!-- ##DOCS-SOURCER-START
{
"originalSources": [
"https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/modules/s3-cloudfront/readme.md",
"https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/modules/s3-cloudfront/variables.tf",
"https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/modules/s3-cloudfront/outputs.tf"
"https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/modules/s3-cloudfront/readme.md",
"https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/modules/s3-cloudfront/variables.tf",
"https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/modules/s3-cloudfront/outputs.tf"
],
"sourcePlugin": "module-catalog-api",
"hash": "62a22806709b7cf7977e231f8b003b40"
"hash": "61171e65f045dde2ff03dec125f535be"
}
##DOCS-SOURCER-END -->
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import VersionBadge from '../../../../../src/components/VersionBadge.tsx';
import { HclListItem, HclListItemDescription, HclListItemTypeDetails, HclListItemDefaultValue, HclGeneralListItem } from '../../../../../src/components/HclListItem.tsx';
import { ModuleUsage } from "../../../../../src/components/ModuleUsage";

<VersionBadge repoTitle="Static Assets Modules" version="0.17.5" lastModifiedVersion="0.17.4"/>
<VersionBadge repoTitle="Static Assets Modules" version="0.17.4" lastModifiedVersion="0.17.4"/>

# S3 Static Website

<a href="https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/modules/s3-static-website" className="link-button" title="View the source code for this module in GitHub.">View Source</a>
<a href="https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/modules/s3-static-website" className="link-button" title="View the source code for this module in GitHub.">View Source</a>

<a href="https://github.com/gruntwork-io/terraform-aws-static-assets/releases/tag/v0.17.4" className="link-button" title="Release notes for only versions which impacted this module.">Release Notes</a>

Expand All @@ -29,39 +29,39 @@ This module creates an AWS S3 bucket that can be used to host a static website.

* Optionally configure a custom domain name for the website.

* Optionally deploy a CDN in front of S3 using the [s3-cloudfront module](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/modules/s3-cloudfront).
* Optionally deploy a CDN in front of S3 using the [s3-cloudfront module](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/modules/s3-cloudfront).

## Learn

The reason to serve static content from S3 rather than from your own app server is that it can significantly reduce the load on your server, allowing it to solely focus on serving dynamic data. This will save you money and make your website run faster. For even bigger improvements in performance, consider deploying a CloudFront Content Distribution Network (CDN) in front of the S3 bucket using the s3-cloudfront module.

### Core concepts

* [Quick Start](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/modules/s3-static-website/core-concepts.md#quick-start)
* [Quick Start](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/modules/s3-static-website/core-concepts.md#quick-start)

* [How to test the website](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/modules/s3-static-website/core-concepts.md#how-to-test-the-website)
* [How to test the website](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/modules/s3-static-website/core-concepts.md#how-to-test-the-website)

* [How to configure HTTPS (SSL) or a CDN?](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/modules/s3-static-website/core-concepts.md#how-to-configure-http)
* [How to configure HTTPS (SSL) or a CDN?](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/modules/s3-static-website/core-concepts.md#how-to-configure-http)

* [How to handle www + root domains](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/modules/s3-static-website/core-concepts.md#how-to-handle)
* [How to handle www + root domains](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/modules/s3-static-website/core-concepts.md#how-to-handle)

* [How do I configure Cross Origin Resource Sharing (CORS)?](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/modules/s3-static-website/core-concepts.md#how-do-i-configure-cross-origin-resource-sharing-cors)
* [How do I configure Cross Origin Resource Sharing (CORS)?](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/modules/s3-static-website/core-concepts.md#how-do-i-configure-cross-origin-resource-sharing-cors)

### Repo organization

* [modules](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/modules): The main implementation code for this repo, broken down into multiple standalone, orthogonal submodules.
* [modules](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/modules): The main implementation code for this repo, broken down into multiple standalone, orthogonal submodules.

* [examples](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/examples): This folder contains working examples of how to use the submodules.
* [examples](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/examples): This folder contains working examples of how to use the submodules.

* [test](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/test): Automated tests for the modules and examples.
* [test](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/test): Automated tests for the modules and examples.

## Deploy

### Non-production deployment (quick start for learning)

If you just want to try this repo out for experimenting and learning, check out the following resources:

* [Examples folder](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/examples): The `examples` folder contains sample code optimized for learning, experimenting, and testing (but not production usage).
* [Examples folder](https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/examples): The `examples` folder contains sample code optimized for learning, experimenting, and testing (but not production usage).

### Production deployment

Expand All @@ -82,7 +82,7 @@ If you want to deploy this repo in production, check out the following resources

module "s_3_static_website" {

source = "git::git@github.com:gruntwork-io/terraform-aws-static-assets.git//modules/s3-static-website?ref=v0.17.5"
source = "git::git@github.com:gruntwork-io/terraform-aws-static-assets.git//modules/s3-static-website?ref=v0.17.4"

# ----------------------------------------------------------------------------------------------------
# REQUIRED VARIABLES
Expand Down Expand Up @@ -267,7 +267,7 @@ module "s_3_static_website" {
# ------------------------------------------------------------------------------------------------------

terraform {
source = "git::git@github.com:gruntwork-io/terraform-aws-static-assets.git//modules/s3-static-website?ref=v0.17.5"
source = "git::git@github.com:gruntwork-io/terraform-aws-static-assets.git//modules/s3-static-website?ref=v0.17.4"
}

inputs = {
Expand Down Expand Up @@ -860,11 +860,11 @@ A value that can be used to chain resources to depend on the website bucket bein
<!-- ##DOCS-SOURCER-START
{
"originalSources": [
"https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/modules/s3-static-website/readme.adoc",
"https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/modules/s3-static-website/variables.tf",
"https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.5/modules/s3-static-website/outputs.tf"
"https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/modules/s3-static-website/readme.adoc",
"https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/modules/s3-static-website/variables.tf",
"https://github.com/gruntwork-io/terraform-aws-static-assets/tree/v0.17.4/modules/s3-static-website/outputs.tf"
],
"sourcePlugin": "module-catalog-api",
"hash": "ba7211fdcc3e9aeb526777b9306b1b7e"
"hash": "4cf33a07f2147d14b3d1b51760e9def9"
}
##DOCS-SOURCER-END -->