Installation and Setup - Cloud
Requirements
- Domain Name
- npm
- CDKTF
- An Amazon AWS account with a ~/.aws configuration and credential file settings
- A hostedZone in Route53 on AWS
- a Stripe Account with api key
- Google Recaptcha key
Full deployment time will take roughly an hour with manual steps between (required for most error free/seamless experience)
Installation
-
clone the project
git clone git@github.com:bmiles-development/s6pack-cloud.git
and cd into the project diractory. -
run
npm update
-
Install AWS, Stripe and dependant CDKTF providers. run
cdktf get
to install the providers. -
Copy and rename the following files:
-
run
cdktf deploy tfStateBackupStack --auto-approve
this stack’s purpose is to setup the Terraform state store on S3 instead of on your local machine. This is for a bunch of good reasons, including better security and avoiding syncing issues when developing with a team. -
In your
.config.hostingStack.yaml
file, change theuseS3TfState
value to true. -
run
cd cdktf.out/stacks/tfStateBackupStack && terraform init -migrate-state
then answeryes
at the prompt -
run
cd ../../../
-
run
cdktf deploy tfStateBackupStack --auto-approve
. This is necessary to work around the chicken-or-the-egg problem of storing the tfStateBackupStack.tfState files on the tfStateBackupStack itself. -
Create AWS [SSM Parameter Store]
SecureString
Parameters (https://us-east-1.console.aws.amazon.com/systems-manager/parameters) for each of the following parameters:Use a dummy email address if response is not necessary:
Google Recaptcha secret key see: https://blog.logrocket.com/implement-recaptcha-react-application/ , or just create an account here https://www.google.com/recaptcha/admin/create .
For localhost captcha testing see: https://developers.google.com/recaptcha/docs/faq#id-like-to-run-automated-tests-with-recaptcha.-what-should-i-do
Free plan id, can leave as is or can be customizable (eg: Free Plan see config.dataStack.yaml)
Paid plan id (eg: Pro Plan see config.dataStack.yaml)
free trial plan id (eg: Business Plan, see config.dataStack.yaml)
-
create emplty values for these parameters for now, we will poplulate them later once they have been created:
Lambda Layers
How to creat new node.js Lambda Layers:
https://dev.to/afrazkhan/how-to-setup-aws-lambda-layers-nodejs-182
1) npm init -i
2) npm i {package_names}
3) add this snippet to package.json "scripts": { "build": "npm install && mkdir -p nodejs && cp -r node_modules nodejs/ && zip -r {file-name}.zip nodejs" }
4)npm run build
Upgrading
Update notes for serverless v2
npm update
sudo npm install cdktf-cli@0.13.0 -g
cdktf provider add “aws@~>4.14” null kreuzwerker/docker archive
cdktf get
npm i -D @types/node //run this if main.ts cant find ‘fs’ or ‘path’
when you run cdktf deploy, it will prompt you to terraform init -upgrade
for each stack (see Upgrading section above, step 3)
Potential Issues and Solutions
cdktf destroy webStackGreen webStackBlue webStackDev
causes error with Appsync: “Error: error deleting Appsync Domain Name “<domain_name_here>”: BadRequestException: Domain name must be disassociated before it can be deleted.” Known issue here https://github.com/hashicorp/terraform-provider-aws/issues/25322.
cdktf destroy hostingStack
causes error with stripe products not deleting. Since the Stripe API does not have a delete endpoint the products have to be manually deleted in the Stripe admin panel. The relevant objects in the terraform.hostingStack.state file needs to be deleted as well, or the cdktf destroy hostingStack
command will continue to fail.
Resource tracking fails when manually deleting resources
The easiest way to no longer track resources that have been manually deleted is to simply delete the resources in the .tfstate and .tfstate.backup files. There are commands to do this but this way seems easier especially for multiple resources (like Stripe prices)