Skip to content

Latest commit

 

History

History

terraform-module

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

🔋 Pleo SPA - Terraform Module

This module creates a complete infrastructure set needed to serve a SPA (Single Page App) on AWS using the cursor files for deployment. Features of this setup:

  • Atomic deployments and instant rollback using per-branch cursor files and Lambda@Edge
  • Optimal latency for infinitely cache-able static assets (on /static/ route) - no edge compute in path
  • CDN-level caching for HTML files and other .well-known files
  • Preview deployments on subdomains in staging environment
  • Security custom headers and blocking robots in staging
  • Origin bucket protection with OAI, so files can only be accessed via Cloudfront

All the resources are created by nested submodules, refer to the documentation of those for details.

How to use

module "my_spa" {
  source = "[email protected]:pleo-io/spa-tools.git//terraform-module?ref=<some_release>"

  app_name      = "my-spa-project"
  subdomain     = "my-spa"
  bucket_prefix = "my-org"

  env         = "staging"
  zone_domain = "example.com"
  providers = {
    aws.global = aws.global
  }
}

AWS Providers

Note that there are two AWS providers, since we need to access two AWS regions

  • all the CDN infra (lambdas, cert) lives in "us-east-1" region (this is required by AWS)
  • the S3 bucket for origin lives in the default region

Requirements

Name Version
aws >= 3.75.2

Providers

No providers.

Modules

Name Source Version
cdn ./modules/frontend-spa-cdn n/a
certificate ./modules/frontend-spa-certificate n/a
dns ./modules/frontend-spa-dns n/a
lambda_role ./modules/frontend-spa-lambda-role n/a
lambdas ./modules/frontend-spa-edge-lambda n/a
s3 ./modules/frontend-spa-s3 n/a

Resources

No resources.

Inputs

Name Description Type Default Required
app_name Name of the app (kebab-case) string n/a yes
block_iframes Should add custom header blocking access via iframes? bool true no
bucket_prefix Prefix for the bucket name. Since S3 bucket live in global scope, it's good prefix it with e.g. your org name string n/a yes
default_repo_branch_name Name of the default branch of the project repo string "master" no
env Environment (production/staging) string n/a yes
is_robots_indexing_allowed Should allow search engine indexing in production? bool true no
subdomain Subdomain where the app lives (e.g. 'hello' if the app lives at hello.example.com) string n/a yes
zone_domain The domain where the app lives (e.g. 'example.com' if the app lives at hello.example.com) string n/a yes

Outputs

Name Description
bucket_deployer_iam_policy_arn n/a