Create AWS infrastructure resources for Single Page Application.
-
create a
infra/main.tfin your project root directory. Replace theaws.profileandspa.hosted_zone. Do not change theaws.region, ACM certificate is required to be inus-east-1.# main.tf provider "aws" { region = "us-east-1" profile = "exampleAdmin" } module "spa" { source = "github.com/louislarry/terraform-aws-spa" hosted_zone = "example.com" force_destroy = true }
-
Init and run terraform apply from the
infradirectorycd infra terraform init terraform apply -
Bob's your uncle.
If hosted_zone is example_com:
- Setup s3 originbucket
example-com-origin - Setup s3 cloudformation log bucket
example-com-cloudfront-log - Add apex and www records to DNS
- Setup cloudfront with alias
example.comandwww.example.com - Configure cloudfront to use lambda@edges
- Create ACM certificate
example.comand*.example.com - Setup all corresponding IAM users, groups, policies, and roles
- Support for
stellar.toml(enable CORS) - Redirect errors (4xx and 5xx) to
/index.html
-
I got following error
Error: Error applying plan: 1 error(s) occurred: * module.spa.aws_cloudfront_distribution.origin: 1 error(s) occurred: * aws_cloudfront_distribution.origin: error creating CloudFront Distribution: InvalidViewerCertificate: The specified SSL certificate doesn't exist, isn't in us-east-1 region, isn't valid, or doesn't include a valid certificate chain. status code: 400, request id: 68fae058-72bc-11e8-a266-5d955149d452Answer:
It's a bug. Please re-run
terraform applyand you should be be fine the second time.
MIT