Common infrastructure for single page applications
Module creates:
- AWS S3 bucket for storing assets
- AWS CloudFront distribution for serving the assets
The master
branch should be used for public production deployments, for development environments you might want to use:
-
Adds a AWS Lambda@Edge which protects the
index.html
using basic auth. Should be used for development and staging environments. -
Adds a AWS Lambda@Edge which routes traffic to Pull Request specific
index.html
-
basic-auth-and-pull-request-router
Combines
basic-auth
andpull-request-router
. Should be used for preview environments.
But Why!?
aws_cloudfront_distribution
useslambda_function_association
blocks to add Lambda@Edge hooks, unfortunatelylambda_function_association
doesn't have anyenabled
flag, which means, as of terraform 0.11, it's not possible to add only some associations based on variables.This could be solved by:
- terraform AWS provider by making
lambda_function_association
it's own resource, which we could toggle by settingcount
- terraform 0.12 which will make the configuration language a lot more powerful
Name | Description | Type | Default | Required |
---|---|---|---|---|
bucket | Kebab-cased bucket name override | string | "" |
no |
certificate_arn | ACM certificate ARN to use instead of the default cloudfront certificate | string | "" |
no |
cloudfront_price_class | CloudFront price class, which specifies where the distribution should be replicated, one of: PriceClass_100, PriceClass_200, PriceClass_All | string | "PriceClass_100" |
no |
domains | List of domains which will serve the application. If empty, will use the default cloudfront domain | list | <list> |
no |
environment | Kebab-cased name of the environment, eg. production, staging, development, preview. Will be included in resource names | string | n/a | yes |
project | Kebab-cased name of the project. Will be included in resource names | string | n/a | yes |
static_cors_max_age_seconds | How long can CORS OPTIONS request responses be cached | string | "3600" |
no |
static_path | Base path for static assets | string | "/static" |
no |
tags | Additional tags to add to each resource that supports them | map | <map> |
no |
Name | Description |
---|---|
bucket_arn | ARN of the created assets S3 bucket |
bucket_name | Name of the created assets S3 bucket |
distribution_arn | ARN of the created assets CloudFront distribution |
distribution_domain | Domain of the created assets CloudFront distribution, eg. d604721fxaaqy9.cloudfront.net. |
distribution_id | ID of the created assets CloudFront distribution |
distribution_url | URL of the created assets CloudFront distribution, eg. https://d604721fxaaqy9.cloudfront.net. |
distribution_zone_id | The CloudFront Route 53 zone ID that can be used to route an Alias Resource Record Set to. |